I've created a basic structure using serverless framework which includes individual lambda functions, GitLab CI/CD with different environments, and a basic API Gateway. I've also added some of the reference links for more information.
- Create a
.env.devfile by taking reference ofenv.dev.example. - Install packages using
npm i.
- Run locally using
npm startor you can also debug using VSCode (F5). - Test and upload files to local S3 for testing (find a sample function inside).
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables must be set in GitLab CI/CD variables.- Add other environments to GitLab CI/CD variables separately for staging and production.
There are following GitLab pipelines that deploy to AWS whenever we push any changes.
- The
stagingbranch is deployed to the staging url. - The
masterbranch is deployed to the production url.
- It compares hash while deploying. So, it skips deploying of a particular lambda function if it hasn't been changed.
- Any change in env needs to re-deploy all the functions using it.
If you want to create packages, use npm run package. This will create a .serverless folder with all the individual zip files.