This project's primary audience is experienced cloud infrastructure folks looking to production-ize a modern Serverless stack in a single AWS account. But, it's also an appropriate place to learn the various parts along the way!
We have three main reference projects from which to learn:
- aws-lambda-serverless-reference: (This project!) Our most basic Serverless reference with a full production infrastructure.
- aws-lambda-dogs: A simple REST API Serverless reference using json-server. If you don't need VPC or are unsure of where to begin, start here.
- badges: Our advanced reference project that includes more complex enhancements like: per-PR environments, github-flow support, promote-to-production artifacts, etc. Once you've mastered manual CF + TF + SLS deploys, come over here and see how far automation can take us!
-
(For Formidables only). Contact Roemer to get three AWS IAM users. The
-developerand-adminusers will be manually attached to the appropriatesandboxstage groups (tf-simple-reference-sandbox-developer,tf-simple-reference-sandbox-admin) for use withserverlesscommands.FIRST.LASTuser: An AWS superadmin that can do things like deploy the bootstrap CloudFormation and service Terraform infrastructures. This user reflects a DevOps lead in a client project. Should only be used foryarn cf:*andyarn tf:*commands.FIRST.LAST-developeruser: A user with IAM group permissions for the specific serverless project +STAGEto update an existing deployment. This reflects an engineer on a client project with limited privileges or maybe a CI system for staging or whatnot. Should only be used foryarn lambda:*commands.FIRST.LAST-adminuser: A user with IAM group permissions for the specific serverless project +STAGEto update + create/delete any deployment. This reflects an engineer on a client project with full privileges over the serverless application, but not the supporting cloud infrastructure. Should only be used foryarn lambda:*commands.
-
Then, follow all the basic directions for installation in the README.
- (For Formidables only). Please set up
aws-vaultper the instructions for your authentication method.
- (For Formidables only). Please set up
-
Check that your credentials are set up for all appropriate work:
# 1. Check CloudFormation as superadmin $ STAGE=sandbox aws-vault exec FIRST.LAST --no-session -- \ yarn cf:bootstrap:status ... "UPDATE_COMPLETE" # (or some other status) # 2. Check Terraform as superadmin # 2.a. Init to appropriate stage backend. $ STAGE=sandbox aws-vault exec FIRST.LAST --no-session -- \ yarn tf:service:init --reconfigure ... Terraform has been successfully initialized! # 2.b. Run plan to see any changes from our code vs. actual infrastructure. $ STAGE=sandbox aws-vault exec FIRST.LAST --no-session -- \ yarn tf:service:plan ... No changes. Infrastructure is up-to-date. # 3. Check Serverless as `-developer` $ STAGE=sandbox aws-vault exec FIRST.LAST-developer --no-session -- \ yarn lambda:info ... Service Information service: sls-simple-reference stage: sandbox region: us-east-1 stack: sls-simple-reference-sandbox ...
tl:dr: usesandboxand only doyarn lambda:*commands for intro exercises.
Lambda
All of the introductory exercises are performed in the pre-existing sandbox environment using only yarn lambda:* commands to do serverless deployments as an -admin or -developer user. This means that you should just let folks know in an appropriate channel that you are "taking over" the environment.
Infrastructure (CloudFormation + Terraform)
Your superadmin user should be reserved only for work on new environments. If you choose to do a new environment, it is very important that you talk to Tyler or Roemer and refactor this application to grep and comment out all sections titled OPTION in serverless.yml and terraform/main.tf to remove all the extra bells and whistles (particularly VPC which is slow and complicates things) in a temporary branch to make your infrastructure work much easier and more focused.
-
Completely review and read the
README.mdone more time and ask questions in a slack channel! -
Do a deployment of the serverless branch as-is off
masterbranch:$ STAGE=sandbox aws-vault exec FIRST.LAST-developer --no-session -- \ yarn lambda:deploy... then go and kick the tires on a URL!
The endpoints created will be listed under
endpointsin the console output. Please note that the endpoints MUST end with/. If the output ishttps://ii178wi5hi.execute-api.us-east-1.amazonaws.com/sandbox/base, then you must usehttps://ii178wi5hi.execute-api.us-east-1.amazonaws.com/sandbox/base/(notice the trailing/) in your browser. -
Delete the serverless application and re-deploy it as-is off
masterbranch:# Be careful! $ STAGE=sandbox aws-vault exec FIRST.LAST-admin --no-session -- \ yarn lambda:_delete # Now, the `lambda:deploy` command needs an `-admin` user to create. $ STAGE=sandbox aws-vault exec FIRST.LAST-admin --no-session -- \ yarn lambda:deploy
-
Create a temporary branch and edit something in
src/server/base.jsthat will be visible from a public URL. Then deploy it and check the results!$ STAGE=sandbox aws-vault exec FIRST.LAST-developer --no-session -- \ yarn lambda:deploy -
See if there are any open issues that need just a serverless / application code fix and try to open a pull request! Or, be a saint and update all the root project dependencies in
package.jsonto keep us up to date, verify everything still works, and open a pull request.
Once you've got the basics of serverless deployment down, you can head over to aws-lambda-dogs Infrastructure Exercises to do things with your AWS superadmin user to the infrastructure (without having to deal with a VPC).