Skip to content

Hooooni98/express-template-on-lambda

Repository files navigation

express-template-on-lambda

infrastructure

Deploy a serverless Express project with a single command.
Have CI/CD - triggers GitHub Actions whenever push to the master branch.

- Express
- AWS Lambda
- AWS Gateway
- AWS ECR

1. Add ".env.sh" file in "set_aws_infra_scripts"

# set_aws_infra_scripts/.env.sh

AWS_ID= #This variable is created automatically
AWS_ACCESS_KEY= 
AWS_SECRET_KEY= 
AWS_REGION=

DOCKER_REPOSITORY_NAME=
DOCKER_IMAGE_NAME=
ECR_ENDPOINT=$AWS_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$DOCKER_REPOSITORY_NAME

LAMBDA_ROLE_NAME=
LAMBDA_FUNCTION_NAME=
LAMBDA_POLICY_ARN=arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

API_GATEWAY_ID= #This variable is created automatically
API_GATEWAY_NAME=
API_GATEWAY_STAGE=

Fill content .env.sh

KEY VALUE
AWS_ACCESS_KEY AWS IAM user access key
AWS_SECRET_KEY AWS IAM user secret key
AWS_REGION AWS Region (ex, ap-northeast-2)
DOCKER_REPOSITORY_NAME Name to use for ecr
DOCKER_IMAGE_NAME Name to use for docker image
LAMBDA_ROLE_NAME Name to use for iam lambda role
LAMBDA_FUNCTION_NAME Name to use for lambda function
API_GATEWAY_NAME Name to use for apigateway
API_GATEWAY_STAGE Name to use for apigateway deploy stage

2. Run "main.sh"

sh ./set_aws_infra_scripts/main.sh

main.sh : Set initial aws infrastructure

  • Make ecr and Push first docker image to ecr
  • Make lambda with docker
  • Make apigateway and invoke lambda

3. Test Request

curl --request GET https://$API_GATEWAY_ID.execute-api.$AWS_REGION.amazonaws.com/dev/hello

4. Set CI/CD env

  1. go "github repo > Settings > Secrets and variables > Actions"
  2. click "New repository secrets"
  3. copy Keys & Values below to your local .env
AWS_ACCESS_KEY
AWS_ID
AWS_REGION
AWS_SECRET_KEY
DOCKER_IMAGE_NAME
ECR_ENDPOINT
LAMBDA_FUNCTION_NAME

How to clear AWS resource

sh ./set_aws_infra_scripts/clear.aws.sh

How to local test

  • Add .env file and Fill below content
# .env

NODE_ENV="local"
$ npm i
$ npm run dev

How to local deploy

  • Excute .deploy.sh file
$ sh ./deploy.sh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors