This is the project repo for the blog post found here: https://fakeweblog.com/how-to-use-terraform-with-serverless-for-lambda-rds-and-internet-access-ba38b8a3579a
- AWS name profile set up: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
- Terraform v0.13.x installed globally (I used tfenv)
- Serverless v2.x globally installed:
npm i -g serverless
First, deploy the infrastructure, which will write files need by serverless.yml
. In the terraform
directory run:
$ terraform init
$ terraform apply -var="stage=dev"
Then in the root of the project, deploy serverless by running:
$ npm run deploy
Finally, test it by running:
$ npm test
Order is important because if you destroy the terraform
infrastructure before serverless
, it'll get stuck since the Security Groups and Subnet IDs are used by serverless. To make sure it's run in the correct order, in the root directory of the project, run:
$ npm run destroy