Skip to content

Commit

Permalink
fix: enables cors support for lambda proxy integrations for python (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Jan 26, 2021
1 parent 1b64a14 commit 44d1ce3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 14 additions & 3 deletions packages/amplify-e2e-tests/src/__tests__/function_3.test.ts
Expand Up @@ -46,7 +46,18 @@ describe('go function tests', () => {
});

describe('python function tests', () => {
const helloWorldSuccessOutput = '{"message":"Hello from your new Amplify Python lambda!"}';
const statusCode: number = 200;
const headers = {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET',
};
const message: string = 'Hello from your new Amplify Python lambda!';
const helloWorldSuccessOutput = {
statusCode: statusCode,
headers: headers,
body: message,
};

let projRoot: string;
let funcName: string;
Expand Down Expand Up @@ -76,7 +87,7 @@ describe('python function tests', () => {
it('add python hello world and mock locally', async () => {
await functionMockAssert(projRoot, {
funcName,
successString: helloWorldSuccessOutput,
successString: helloWorldSuccessOutput.body,
eventFile: 'src/event.json',
timeout: 120,
}); // will throw if successString is not in output
Expand All @@ -86,7 +97,7 @@ describe('python function tests', () => {
const payload = '{"test":"event"}';
await amplifyPushAuth(projRoot);
const response = await functionCloudInvoke(projRoot, { funcName, payload });
expect(JSON.parse(response.Payload.toString())).toEqual(JSON.parse(helloWorldSuccessOutput));
expect(JSON.parse(response.Payload.toString())).toEqual(JSON.parse(JSON.stringify(helloWorldSuccessOutput)));
});
});

Expand Down
Expand Up @@ -2,5 +2,11 @@ def handler(event, context):
print('received event:')
print(event)
return {
'message': 'Hello from your new Amplify Python lambda!'
}
'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!"
}

1 comment on commit 44d1ce3

@ashleyoldershaw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix! I had to lift this out of the PR just now as it's not in the main branch yet (I created the function today).

Just thought you'd want to know you've already helped someone out within 24 hours ;)

Please sign in to comment.