https://github.com/geoffdutton/serverless-rds-aws-structure
An full example of setting up the infrastructure and project for a Serverless function that connects to RDS and the internet.
https://github.com/geoffdutton/serverless-rds-aws-structure
lambda rds serverless terraform
Last synced: 7 months ago
JSON representation
An full example of setting up the infrastructure and project for a Serverless function that connects to RDS and the internet.
- Host: GitHub
- URL: https://github.com/geoffdutton/serverless-rds-aws-structure
- Owner: geoffdutton
- Created: 2020-10-29T22:04:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-30T22:37:36.000Z (over 5 years ago)
- Last Synced: 2025-05-15T02:37:20.770Z (11 months ago)
- Topics: lambda, rds, serverless, terraform
- Language: HCL
- Homepage:
- Size: 102 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless RDS with Lambda
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
## Perquisites
- 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](https://github.com/tfutils/tfenv))
- Serverless v2.x globally installed: `npm i -g serverless`
## Deploying
First, deploy the infrastructure, which will write files need by `serverless.yml`. In the `terraform` directory run:
```bash
$ terraform init
$ terraform apply -var="stage=dev"
```
Then in the root of the project, deploy serverless by running:
```bash
$ npm run deploy
```
Finally, test it by running:
```bash
$ npm test
```
## Destroying
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:
```bash
$ npm run destroy
```