Skip to content

apigateway-sqs-integration-mapping-template-snippet #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apigateway-sqs-integration-mapping-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Amazon API Gateway Access Logging Setup

This snippet assumes that Amazon API Gateway logs requests to Amazon CloudWatch Logs using JSON and the following log format:

```json
{
"requestId":"$context.requestId",
"ip": "$context.identity.sourceIp",
"apiKey": "$context.identity.apiKey",
"requestTime":"$context.requestTime",
"httpMethod":"$context.httpMethod",
"routeKey":"$context.routeKey",
"path":"$context.path",
"status": $context.status,
"protocol":"$context.protocol",
"integrationStatus": $context.integrationStatus,
"integrationLatency": $context.integrationLatency,
"responseLatency":$context.responseLatency,
"responseLength": $context.responseLength
}
```

You can modify log format to fit your needs (make sure to update code snippet if field names change).


See documentation for more details on how to set up API Gateway logging in HTTP (https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging.html) and REST (https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html) APIs.
45 changes: 45 additions & 0 deletions apigateway-sqs-integration-mapping-template/snippet-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"title": "Mapping template for API Gateway with SQS integration",
"description": "Provides a mapping template for API Gateway and SQS integration",
"type": "Integration",
"services": ["apigw", "sqs"],
"tags": [],
"languages": ["vtl"],
"introBox": {
"headline": "How it works",
"text": [
"These snippets can be used to send and receive messages to an existing SQS queue.",
"When creating the integration, ensure to have the below configuration to use the mapping template:"
"1. For Path override the value must be given as '<AWS account number>/<SQS Queue name>' ",
"2. The header 'Content-Type' should have the value 'application/x-www-form-urlencoded' (include the single quotes in the value)",
"3. IAM role with appropriate sns:publish IAM permission for sqs:publish and sqs:receive",
"4. Select the integration HTTP method as 'POST'"
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-snippets/tree/main/apigateway-sqs-integration-mapping-template"
}
},
"snippets": [
{
"title": "Use the following mapping template to send messages to SQS queue:",
"snippetPath": "snippet-send.txt",
"language": "vtl"
},
{
"title": "Use the following mapping template to poll for or retrieve messages from the specified queue:",
"snippetPath": "snippet-receive.txt",
"language": "vtl"
}
],
"authors": [
{
"headline": "Presented by Pallavi Bhat",
"name": "Pallavi Bhat",
"image": "https://drive.google.com/file/d/1xYr8HfVnLZOMmhAc9hSsyj_O85yyznF7/view?usp=sharing",
"bio": "Pallavi is a Cloud Support Enginner focusing on serverless at Amazon Web Services.",
"linkedin": "https://www.linkedin.com/in/pallavi-bhat11/"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Action=ReceiveMessage&MaxNumberOfMessages=10&WaitTimeSeconds=10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Action=SendMessage&MessageBody=$util.urlEncode($input.body)