Skip to content

Commit 9aa0557

Browse files
Merge branch 'aws-samples:main' into vamsipulikonda-rest-api-with-alb
2 parents e8b4eb5 + 0ded831 commit 9aa0557

File tree

1,895 files changed

+80227
-2081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,895 files changed

+80227
-2081
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Create and Update Releases
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
get-release:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
latest_release: ${{ steps.get_latest_release.outputs.latest_release }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Get the latest release tag
18+
id: get_latest_release
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
LATEST_RELEASE=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' || echo "none")
23+
echo "Latest release tag: $LATEST_RELEASE"
24+
echo "::set-output name=latest_release::$LATEST_RELEASE"
25+
echo "latest_release=${latest_release}" >> $GITHUB_ENV
26+
continue-on-error: true
27+
28+
create-release:
29+
needs: get-release
30+
runs-on: ubuntu-latest
31+
if: needs.get-release.outputs.latest_release == ''
32+
steps:
33+
- name: print latest release output
34+
run: echo "Latest release ${{ needs.get-release.outputs.latest_release }}"
35+
36+
- name: Checkout repository
37+
uses: actions/checkout@v3
38+
39+
- name: Release doesn't exist so create one
40+
id: create_release
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
gh release create v1.0.0 --notes "Initial release v1.0.0" --prerelease=false
45+
echo "Release created"
46+
47+
- name: Zip files of folders
48+
id: zip_folders
49+
run: |
50+
mkdir -p temp
51+
for folder in */; do
52+
if [ -d "$folder" ]; then
53+
folder_name=$(basename "$folder")
54+
zip -r "temp/${folder_name}.zip" "$folder_name"
55+
fi
56+
done
57+
echo "Zip files created"
58+
59+
- name: upload files to the release
60+
id: upload_files
61+
env:
62+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
for file in temp/*.zip; do
65+
if [ -f "$file" ]; then
66+
gh release upload v1.0.0 "$file" --clobber
67+
echo "Uploaded $file, waiting to avoid rate limits..."
68+
sleep 3
69+
else
70+
echo "File $file not found"
71+
fi
72+
done
73+
74+
update-release:
75+
needs: get-release
76+
runs-on: ubuntu-latest
77+
if: needs.get-release.outputs.latest_release != ''
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v3
81+
82+
- name: Fetch latest tags
83+
run: |
84+
git fetch --tags
85+
86+
- name: Get changed files
87+
id: get_changes
88+
run: |
89+
if [ -n "${{ needs.get-release.outputs.latest_release }}" ]; then
90+
git fetch origin refs/tags/${{ needs.get-release.outputs.latest_release }}:refs/tags/${{ needs.get-release.outputs.latest_release }}
91+
changed_files=$(git diff --name-only ${{ needs.get-release.outputs.latest_release }} HEAD)
92+
echo "Changed files: $changed_files"
93+
echo "$changed_files" > changed_files.txt
94+
else
95+
echo "No latest release found"
96+
echo "" > changed_files.txt
97+
fi
98+
99+
- name: Identify changed folders
100+
id: identify_folders
101+
run: |
102+
if [ -s changed_files.txt ]; then
103+
changed_folders=$(awk -F/ '{print $1}' changed_files.txt | sort | uniq)
104+
echo "Changed folders: $changed_folders"
105+
echo "$changed_folders" > changed_folders.txt
106+
else
107+
echo "No changed files"
108+
echo "" > changed_folders.txt
109+
fi
110+
111+
- name: Archive changed folders
112+
run: |
113+
mkdir -p temp_archives
114+
while IFS= read -r folder; do
115+
if [ -d "$folder" ]; then
116+
zip -r "temp_archives/$folder.zip" "$folder"
117+
echo "Archived $folder"
118+
else
119+
echo "Folder $folder does not exist"
120+
fi
121+
done < changed_folders.txt
122+
123+
- name: Upload archives to release
124+
if: needs.get-release.outputs.latest_release != ''
125+
env:
126+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
run: |
128+
while IFS= read -r folder; do
129+
archive="temp_archives/$folder.zip"
130+
if [ -f "$archive" ]; then
131+
gh release upload ${{ needs.get-release.outputs.latest_release }} "$archive" --clobber
132+
echo "Uploaded $archive, waiting to avoid rate limits..."
133+
else
134+
echo "Archive $archive not found"
135+
fi
136+
done < changed_folders.txt

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- name: Get changed files using defaults
1616
id: changed-files
17-
uses: tj-actions/changed-files@v41
17+
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275
1818
with:
1919
separator: ","
2020

.github/workflows/schema-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- name: Get changed files using defaults
1717
id: changed-files
18-
uses: tj-actions/changed-files@v41
18+
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275
1919
with:
2020
separator: ","
2121

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,7 @@ terraform.rc
234234

235235
#Ignore Intellij files
236236
*.iml
237-
*.idea
237+
*.idea
238+
239+
# This file gets generated as part of Maven shade plugin which can be ignored
240+
dependency-reduced-pom.xml
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
## AWS API Gateway to AWS SQS
2+
3+
This pattern creates a REST API Gateway that directly integrates with AWS SQS to read messages.
4+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/
5+
6+
**Important**: This application uses various AWS services that incur costs beyond the Free Tier usage. Please review the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
7+
8+
## Requirements
9+
10+
- An [AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) with appropriate IAM permissions to make service calls and manage AWS resources
11+
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
12+
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed
13+
- [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
14+
15+
## Deployment Instructions
16+
17+
1. Clone the GitHub repository:
18+
```git clone https://github.com/aws-samples/serverless-patterns```
19+
20+
2. Navigate to the pattern directory:
21+
```cd APIGateway-SQS-ReceiveMessages```
22+
23+
3. Deploy using AWS SAM:
24+
```sam deploy --guided```
25+
26+
During the prompts:
27+
- Enter a stack name
28+
- Select your desired AWS Region
29+
- Allow SAM CLI to create IAM roles with required permissions
30+
31+
After initial deployment with sam deploy --guided, subsequent deployments can use sam deploy with the saved configuration (samconfig.toml).
32+
33+
Note the outputs from the deployment process, as they contain resource names and/or ARNs needed for testing.
34+
35+
## How it works
36+
37+
This pattern creates an Amazon API Gateway REST API endpoint that directly connects to Amazon SQS using service integrations. Users can retrieve messages by calling the GET method of the invoke URL (API Gateway) provided in the Stack Output.
38+
39+
The invoke URL supports query string parameters such as MaxNumberOfMessages=5, VisibilityTimeout=15, and AttributeName=All to customize the response.
40+
41+
For detailed parameter definitions, refer to the [AWS API Reference Documentation](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html).
42+
43+
## Usage Example and Consideration
44+
45+
This pattern is ideal for scenarios where you need to retrieve messages from SQS via HTTPS without using AWS SDK. Common use cases include:
46+
Web applications that need to poll SQS queues for new messages, Mobile applications requiring secure access to SQS messages, Third-party integrations where direct AWS SDK access isn't practical, Legacy system integrations that support only HTTP/HTTPS protocols, Development environments where simplified queue access is preferred.
47+
48+
Please review [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html) and [SQS Quotas](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html) for service limits before implementation.
49+
50+
## Testing
51+
52+
Follow these steps to test the integration:
53+
54+
1. First, send test messages to the queue:
55+
```chmod +x send_message_to_queue.sh```
56+
57+
```./send_message_to_queue.sh {queueURL} {number of messages}```
58+
59+
Example:
60+
```./send_message_to_queue.sh https://sqs.us-east-1.amazonaws.com/210987654321/myQueue 3```
61+
62+
2. Then, retrieve messages using the API Gateway endpoint:
63+
64+
Basic retrieval:
65+
```curl --location --request GET '{ApiEndpoint output value}'```
66+
67+
Advanced retrieval with parameters:
68+
```curl --location --request GET '{ApiEndpoint output value}?MaxNumberOfMessages=5&VisibilityTimeout=15&AttributeName=All'```
69+
70+
Parameter details are available in the [AWS API Reference Documentation](
71+
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html).
72+
73+
## Expected Output
74+
75+
When Queue is Empty:
76+
```json
77+
{
78+
"ReceiveMessageResponse": {
79+
"ReceiveMessageResult": {
80+
"messages": null
81+
},
82+
"ResponseMetadata": {
83+
"RequestId": "RequestId"
84+
}
85+
}
86+
}
87+
```
88+
89+
When Queue has Messages:
90+
```json
91+
{
92+
"ReceiveMessageResponse": {
93+
"ReceiveMessageResult": {
94+
"messages": [
95+
{
96+
"Attributes": null,
97+
"Body": "messageBody",
98+
"MD5OfBody": "MD5OfBody",
99+
"MD5OfMessageAttributes": null,
100+
"MessageAttributes": null,
101+
"MessageId": "Queue Message ID",
102+
"ReceiptHandle": "ReceiptHandle"
103+
}
104+
]
105+
},
106+
"ResponseMetadata": {
107+
"RequestId": "requestID"
108+
}
109+
}
110+
}
111+
```
112+
113+
## Cleanup
114+
115+
Delete the stack using SAM:
116+
```
117+
sam delete
118+
```
119+
120+
Confirm when prompted to delete the stack and its resources.
121+
122+
Note: You can also use `sam delete --no-prompts` to skip confirmation steps.
123+
124+
---
125+
126+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
127+
SPDX-License-Identifier: MIT-0
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"title": "Amazon API Gateway to Amazon SQS",
3+
"description": "Create a REST API Gateway to receive messages from SQS queue.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "AWS SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern creates an Amazon API gateway REST API endpoint. The endpoint uses service integrations to directly connect to Amazon SQS that reads messages from the SQS.",
11+
"Users can simply call the GET Method of invoke URL( API Gateway) that is returned as part of the Stack Output.",
12+
"Invoke URL can also be used with query string parameters like MaxNumberOfMessages=5 VisibilityTimeout=15 AttributeName=All to get the desired output.",
13+
"Useful with Frontend application that would like to interact with sqs via https protocol to read messages from the SQS queue Avoid any useage of AWS SDK since request to SQS can be made via simple http request.",
14+
"Please also consider looking at AWS API Gateway and AWS SQS quotas for different limits supported by the services when working with this pattern."
15+
]
16+
},
17+
"gitHub": {
18+
"template": {
19+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/APIGateway-SQS-ReceiveMessages",
20+
"templateURL": "serverless-patterns/APIGateway-SQS-ReceiveMessages",
21+
"projectFolder": "APIGateway-SQS-ReceiveMessages",
22+
"templateFile": "template.yaml"
23+
}
24+
},
25+
"resources": {
26+
"bullets": [
27+
{
28+
"text": "Working on integration of AWS Services with API Gateway",
29+
"link": "https://repost.aws/knowledge-center/api-gateway-proxy-integrate-service"
30+
},
31+
{
32+
"text": "API Gateway Documentation",
33+
"link": "https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html"
34+
},
35+
{
36+
"text":"AWS SQS Documentation",
37+
"link":"https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html"
38+
},
39+
{
40+
"text":"AWS API Gateway Quotas",
41+
"link":"https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html"
42+
},
43+
{
44+
"text":"AWS SQS Quotas",
45+
"link":"https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html"
46+
}
47+
]
48+
},
49+
"deploy": {
50+
"text": [
51+
"sam deploy"
52+
]
53+
},
54+
"testing": {
55+
"text": [
56+
"See the GitHub repo for detailed testing instructions."
57+
]
58+
},
59+
"cleanup": {
60+
"text": [
61+
"Delete the stack: <code>sam delete</code>"
62+
]
63+
},
64+
"authors": [
65+
{
66+
"name": "Yogesh Nain",
67+
"image": "link-to-your-photo.jpg",
68+
"bio": "Yogesh is Cloud Support Engineer and SME of Lambda, API Gateway at Amazon Web Services.",
69+
"linkedin": "https://www.linkedin.com/in/yogesh-nain-a54133170/"
70+
}
71+
]
72+
}

0 commit comments

Comments
 (0)