Reputation: 6255
I'm learning about AWS, and very outside my element, which is typically embedded software. I'm porting this question from Software Engineering after several days of no traction there.
Problem/question: in trying to set up a S3 bucket where file additions trigger a Lambda, how can one debug or trace the sequence of events from file addition to SNS notification to Lambda execution?
I'm trying to set up the following:
I'm using the AWS CLI
for everything, and for the immediate future, I am limited to using LocalStack
to substitute for "real" AWS.
What I've done so far (simplified):
aws s3 mb my-bucket --endpoint-url=http://localhost:4572
)aws:policy/AWSLambdaFullAccess
aws lambda add-permission --function-name first_lambda --action lambda:InvokeFunction --statement-id sns-invoke-lambda --principal sns.amazonaws.com --endpoint-url=http://localhost:4574
)aws sns create-topic --name my-topic --endpoint-url=http://localhost:4575
)aws sns subscribe --topic-arn arn:aws:sns:us-east-1:000000000000:my-topic --protocol lambda --notification-endpoint arn:aws:lambda:us-east-1:000000000000:function:first_lambda --endpoint-url=http://localhost:4575
)aws s3api put-bucket-notification-configuration --bucket my-bucket --notification-configuration file://s3-ObjectCreated_notify.json --endpoint-url=http://localhost:4572
)aws lambda invoke --function-name first_lambda outfile.txt --endpoint-url=http://localhost:4574
)This is my "hello-world" Lambda function, naively cobbled together from here and here:
import json
def lambda_handler(event, context):
print("Hello from Lambda!")
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
This is my put-bucket-notification-configuration file:
{
"TopicConfigurations": [
{
"TopicArn": "arn:aws:sns:us-east-1:000000000000:my-topic",
"Events": [
"s3:ObjectCreated:*"
]
}
]
}
My problem is this: I'm not sure how to test success or failure of the "pipeline" I've tried to build from S3 Bucket to Lambda invocation.
(Please correct misunderstanding:) if I'm manually invoking a Lambda function, the "context of execution" is the shell from which I issue the AWS CLI request. But when the "context of execution" is the "pipeline" that I built from S3 Bucket to SNS notification to Lambda, I don't understand where the Lambda's print
statement or return-status will be directed to. I.e. when I invoke the Lambda manually, my shell gets the return-status, and the print
statement seems to get directed to the outfile I specify; e.g.:
$ aws lambda invoke --function-name first_lambda outfile.txt --endpoint-url=http://localhost:4574
{
"StatusCode": 200
}
...but how can I test end-to-end functionality, or failure, between bucket object-creation to SNS notification to Lambda invocation since there's no outfile for print
s to be directed to, and no "context" to which to return a status to?
Upvotes: 1
Views: 3396
Reputation: 518
The output of your print statements would be clearly logged on AWS CloudWatch, also every error will be logged there.
So be sure to visit cloudwatch and check what is happening behind the scenes.
Docs: https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/index.html
Upvotes: 2