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: about 1 year 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.
- Host: GitHub
- URL: https://github.com/danieldacosta/apigateway-sqs-lambda
- Owner: DanielDaCosta
- License: mit
- Created: 2020-05-31T23:55:48.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-26T17:16:28.000Z (about 4 years ago)
- Last Synced: 2025-01-11T01:10:38.346Z (over 1 year ago)
- Topics: apigateway, apigateway-sqs-lambda, lambda, sqs, sqs-queue
- Language: HCL
- Homepage:
- Size: 98.6 KB
- Stars: 15
- Watchers: 2
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 = <