How to receive a file with an Aws Lambda (python)
You are using API Gateway so your lambda event will map to something like this (from Amazon Docs):
{ "resource": "Resource path", "path": "Path parameter", "httpMethod": "Incoming request's method name" "headers": {String containing incoming request headers} "multiValueHeaders": {List of strings containing incoming request headers} "queryStringParameters": {query string parameters } "multiValueQueryStringParameters": {List of query string parameters} "pathParameters": {path parameters} "stageVariables": {Applicable stage variables} "requestContext": {Request context, including authorizer-returned key-value pairs} "body": "A JSON string of the request payload." "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"}
You can pass the file as a base64 value in the body and decode it in your lambda function. Take the following Python snippet
def lambda_handler(event, context): data = json.loads(event['body']) # Let's say we user a regular <input type='file' name='uploaded_file'/> encoded_file = data['uploaded_file'] decoded_file = base64.decodestring(encoded_file) # now save it to S3