Forked from djg07/gist:1dc4196116e9eb55c40766d4fdc76c3b
Created
October 6, 2020 01:32
-
-
Save cengkuru/380bd54c54bcd710bbf95a87af351bee to your computer and use it in GitHub Desktop.
Resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S3 PutObject Role | |
--- | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": "s3:PutObject", | |
"Resource": "*" | |
} | |
] | |
} | |
AWSLambdaBasicExecution Role | |
--- | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents" | |
], | |
"Resource": "*" | |
} | |
] | |
} | |
Python Code | |
--- | |
#Talk python to me | |
import json | |
import boto3 | |
s3 = boto3.client('s3') | |
def lambda_handler(event, context): | |
bucket ='aws-simplified-transactions' | |
transactionToUpload = {} | |
transactionToUpload['transactionId'] = '12345' | |
transactionToUpload['type'] = 'PURCHASE' | |
transactionToUpload['amount'] = 20 | |
transactionToUpload['customerId'] = 'CID-11111' | |
fileName = 'CID-11111' + '.json' | |
uploadByteStream = bytes(json.dumps(transactionToUpload).encode('UTF-8')) | |
s3.put_object(Bucket=bucket, Key=fileName, Body=uploadByteStream) | |
print('Put Complete') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment