An open API service indexing awesome lists of open source software.

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.

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
```