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

https://github.com/danieldacosta/apigateway-sqs-lambda

Setting up an API Gateway endpoint that takes records, put them into an SQS queue that triggers an Event Source for a Lambda function.
https://github.com/danieldacosta/apigateway-sqs-lambda

apigateway apigateway-sqs-lambda lambda sqs sqs-queue

Last synced: 7 months ago
JSON representation

Setting up an API Gateway endpoint that takes records, put them into an SQS queue that triggers an Event Source for a Lambda function.

Awesome Lists containing this project

README

          

# Terraform ApiGateway-SQS-Lambda integration
Example of a terraform script to setup an API Gateway endpoint that takes records and puts them into an SQS queue that will trigger an Event Source for AWS Lambda.

When deployed, you'll have a public endpoint that will write to SQS with a Lambda function that will consume from it.

For more informations check the Medium post [Building an ApiGateway-SQS-Lambda integration using Terraform](https://medium.com/@danieldacosta_75030/building-an-apigateway-sqs-lambda-integration-using-terraform-5617cc0408ad).

## Getting Started
This project follows the following file structure:
```
├── LICENSE
├── README.md
├── apiGateway.tf
├── iam.tf
├── lambda: folder for lambda code
│   ├── handler.py
│   └── sqs-integration-dev-lambda.zip
├── lambda.tf
├── main.tf
├── policies: all policies created
│   ├── api-gateway-permission.json
│   └── lambda-permission.json
├── sqs.tf
├── terraform.tfstate
├── terraform.tfstate.backup
├── variables.tf: defining variables that will be used inside terraform templates
└── variables.tfvars: input variables
```

## Usage
Run ```terraform init``` to initialize the working directory containing Terraform configuration files.

For good practices, you should confirm your changes using ```terraform plan -var-file="variables.tfvars"```

Run ```terraform apply -var-file="variables.tfvars"``` for applying environment variables.

## Details

### SQS

Building SQS

```
resource "aws_sqs_queue" "queue" {
name = "apigateway-queue"
delay_seconds = 0
max_message_size = 262144
message_retention_seconds = 86400
receive_wait_time_seconds = 10

tags = {
Product = local.app_name
}
}
```

### IAM

Defining permissions so that API Gateway has the necessary permissions to SendMessage to SQS queue.

```
resource "aws_iam_role" "apiSQS" {
name = "apigateway_sqs"

assume_role_policy = <