Skip to content

Commit

Permalink
fix: adding JSON stringify to example python function
Browse files Browse the repository at this point in the history
We need a JSON string for the body in order to access it in our response message. See this comment: aws-amplify/amplify-js#6390 (comment)

I had this issue with my own function which was returning null on my JSON.stringify(response). I found the above comment and it made it work! i.e. I could access the return body.
  • Loading branch information
ashleyoldershaw committed Jan 27, 2021
1 parent 525deb6 commit 268679b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('python function tests', () => {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET',
};
const message: string = 'Hello from your new Amplify Python lambda!';
const message: string = JSON.stringify('Hello from your new Amplify Python lambda!');
const helloWorldSuccessOutput = {
statusCode: statusCode,
headers: headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json

def handler(event, context):
print('received event:')
print(event)

return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body': "Hello from your new Amplify Python lambda!"
'body': json.dumps('Hello from your new Amplify Python lambda!')
}

0 comments on commit 268679b

Please sign in to comment.