Reputation: 3296
I am trying to deploy my first function on AWS Lambda that should store results on my S3 instance following this tutorial. To be sure I have the permission to write files to the S3 bucket I've created I added the code below the commented one into the Function code section.
# import json
# def lambda_handler(event, context):
# # TODO implement
# return {
# 'statusCode': 200,
# 'body': json.dumps('Hello from fucking Lambda!')
# }
import boto3
def lambda_handler(event, context):
s3 = boto3.resource("s3") # pointer to AWS S3 service
bucket_name = "my-own-bucket" # bucket for saving our data
file_name = "HelloWorld.txt" # dummy file
body = event['key1'] + ' ' + event['key2'] + event['key3']
# "Hello World!" from event input
s3.Bucket(bucket_name).put_object(Key=file_name, Body=body)
# write object to bucket
return f"Succeed! Find your new {file_name} file in {bucket_name} bucket ;)"
I used the template test event:
My code automatically saved, so I opened the S3 bucket again and verified that a HelloWorld.txt file existed. But it didn't. And the execution results were:
Response:
{
"statusCode": 200,
"body": "\"Hello from Lambda!\""
}
Request ID:
"93c1c61c-73cf-4308-9a88-0e8771612b8e"
Function logs:
START RequestId: 93c1c61c-73cf-4308-9a88-0e8771612b8e Version: $LATEST
END RequestId: 93c1c61c-73cf-4308-9a88-0e8771612b8e
REPORT RequestId: 93c1c61c-73cf-4308-9a88-0e8771612b8e Duration: 0.32 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 43 MB
Like if the commented code had still been taken into account.
Upvotes: 0
Views: 88
Reputation: 238209
It could be due to following reasons:
Deploy
button.Upvotes: 2