Skip to content

Commit 7abd24c

Browse files
committed
CHANGES
Updated environment variable name to AWS_REGION_NAME. Removed credentials input in lambda handler, to leverage on AWS CLI profile. Updatd README on include instructions for AWS CLI configuration.
1 parent 65c44aa commit 7abd24c

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

sqs-lambda-s3-terraform-python/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ The SQS queue is configured as a trigger for the Lambda function. Whenever a mes
9595
9696
1. Generate an access key pair (access key and secret access key) for IAM user in the AWS CLI. The key pair will be used while running the test script.
9797
98+
1. Create an AWS CLI profile (see [AWS CLI Configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration)), using the key pair in the previous step:
99+
100+
```
101+
aws configure
102+
```
103+
98104
1. Update the AWS region in the test script `send_sqs_event.py` with the region, in which the SQS queue will be created:
99105
100106
```
@@ -107,19 +113,14 @@ The SQS queue is configured as a trigger for the Lambda function. Whenever a mes
107113
python send_sqs_event.py
108114
```
109115
110-
1. Enter the Access Key and Secret Access Key when prompted:
111-
112-
```
113-
Enter Access Key: ********************
114-
Enter Secret Access Key: ****************************************
115-
```
116-
117116
1. Check the S3 bucket to see if a new JSON object has been created:
118117
119118
```
120-
aws s3 ls --region ap-south-1 my-bucket-20250329
119+
aws s3 ls [bucket-name]
121120
```
122121
122+
Alternately, the S3 bucket can be looked up on the AWS Console.
123+
123124
## Cleanup
124125
125126
1. Delete the AWS resources through Terraform:

sqs-lambda-s3-terraform-python/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def lambda_handler(event, context):
1010
print(context)
1111
file_name = 'request_' + json.loads(event['Records'][0]['body'])["uniqueID"] + '.json'
1212
request_body = event['Records'][0]['body']
13-
aws_region = os.getenv('AWS_REGION')
13+
aws_region = os.getenv('AWS_REGION_NAME')
1414
s3_bucket_ident = os.getenv('S3_BUCKET_NAME')
1515
config = Config(region_name=aws_region)
1616
s3_client = boto3.client('s3',config=config)

sqs-lambda-s3-terraform-python/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "aws_lambda_function" "event-processor" {
2929
role = aws_iam_role.event-processor-exec-role.arn
3030
environment {
3131
variables = {
32-
AWS_REGION = var.aws_region_name
32+
AWS_REGION_NAME = var.aws_region_name
3333
S3_BUCKET_NAME = var.s3_bucket_name
3434
}
3535
}

sqs-lambda-s3-terraform-python/send_sqs_event.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import boto3
22
from botocore.config import Config
33
import json
4-
import maskpass
54
import uuid
65

7-
access_key = maskpass.askpass('Enter Access Key: ')
8-
secret_access_key = maskpass.askpass('Enter Secret Access Key: ')
6+
97
config = Config(region_name='ap-south-1')
108
sqs_client = boto3.client('sqs',
11-
aws_access_key_id=access_key,
12-
aws_secret_access_key=secret_access_key,
139
config=config)
1410
uniq_id = str(uuid.uuid4())
1511
response = sqs_client.send_message(

0 commit comments

Comments
 (0)