Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST and PATCH methods does not works in api-cors-lambda-crud-dynamodb #362

Closed
vishalisakar opened this issue Nov 6, 2020 · 1 comment · Fixed by #468
Closed

POST and PATCH methods does not works in api-cors-lambda-crud-dynamodb #362

vishalisakar opened this issue Nov 6, 2020 · 1 comment · Fixed by #468
Assignees
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort language/typescript Related to Typescript examples p2

Comments

@vishalisakar
Copy link

vishalisakar commented Nov 6, 2020

I have cloned the example api-cors-lambda-crud-dynamodb in typescript language and followed the instruction given in the repository. I was success in deploying and tried the endpoint in the Postman. only the get all, get one item, and delete items endpoints works. My write operation such as create and update methods does not work. It throws following errors.

This is an error I get for Creat method using POST Variable:

status: 502 Bad Gateway

{
    "message": "Internal server error"
}

My log result for create method

Execution log for request c5d51a2f-1ca2-4dea-bdc2-75397c95b003
Fri Nov 06 08:24:12 UTC 2020 : Starting execution for request: c5d51a2f-1ca2-4dea-bdc2-75397c95b003
Fri Nov 06 08:24:12 UTC 2020 : HTTP Method: POST, Resource Path: /items
Fri Nov 06 08:24:12 UTC 2020 : Method request path: {}
Fri Nov 06 08:24:12 UTC 2020 : Method request query string: {}
Fri Nov 06 08:24:12 UTC 2020 : Method request headers: {}
Fri Nov 06 08:24:12 UTC 2020 : Method request body before transformations: {
    "name": "abc"
}
Fri Nov 06 08:24:12 UTC 2020 : Endpoint request URI: https://lambda.ap-south-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-south-1:146331168322:function:ApiLambdaCrudDynamoDBExam-createItemFunction8D47E4-16LPD21SPFKKP/invocations
Fri Nov 06 08:24:12 UTC 2020 : Endpoint request headers: {x-amzn-lambda-integration-tag=c5d51a2f-1ca2-4dea-bdc2-75397c95b003, Authorization=*************************************************************************************************************************************************************************************************************************************************************************************************************************23d4c0, X-Amz-Date=20201106T082412Z, x-amzn-apigateway-api-id=uqsoztcq5a, X-Amz-Source-Arn=arn:aws:execute-api:ap-south-1:146331168322:uqsoztcq5a/test-invoke-stage/POST/items, Accept=application/json, User-Agent=AmazonAPIGateway_uqsoztcq5a, X-Amz-Security-Token=IQoJb3JpZ2luX2VjEKj//////////wEaCmFwLXNvdXRoLTEiRzBFAiBPlmLGZpuQVqHV+R/Rj9Mmwbh4uAsASruyydgOGfGy6gIhAINaaAae2Gzw4X1sor/DkzqxRjuehy4QGY67VNlIIaPdKrYDCBEQAhoMNTA3MDY5NzE3ODU1IgzQWqzbaYqD/AHzTM8qkwNo03uWX/lfGW9UPGW1r/R3uSIVAEhH/poalHcLvJItixPxCRh6n5skwSdmpafGeEcHuU0avRtz2h+zUHrTI2YngUIXJIX/EIQtKabc/Ey3DWSWdwvPv1iGtgw2mAgeHXjA1P4vNrlFYaOi4HUX [TRUNCATED]
Fri Nov 06 08:24:12 UTC 2020 : Endpoint request body after transformations: {"resource":"/items","path":"/items","httpMethod":"POST","headers":null,"multiValueHeaders":null,"queryStringParameters":null,"multiValueQueryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"resourceId":"mf0rg7","resourcePath":"/items","httpMethod":"POST","extendedRequestId":"Vk43CHByBcwFXtA=","requestTime":"06/Nov/2020:08:24:12 +0000","path":"/items","accountId":"146331168322","protocol":"HTTP/1.1","stage":"test-invoke-stage","domainPrefix":"testPrefix","requestTimeEpoch":1604651052953,"requestId":"c5d51a2f-1ca2-4dea-bdc2-75397c95b003","identity":{"cognitoIdentityPoolId":null,"cognitoIdentityId":null,"apiKey":"test-invoke-api-key","principalOrgId":null,"cognitoAuthenticationType":null,"userArn":"arn:aws:iam::146331168322:root","apiKeyId":"test-invoke-api-key-id","userAgent":"aws-internal/3 aws-sdk-java/1.11.848 Linux/4.9.217-0.3.ac.206.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.262-b10 java/1.8.0_262 vendor/Oracle_Corpora [TRUNCATED]
Fri Nov 06 08:24:12 UTC 2020 : Sending request to https://lambda.ap-south-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-south-1:146331168322:function:ApiLambdaCrudDynamoDBExam-createItemFunction8D47E4-16LPD21SPFKKP/invocations
Fri Nov 06 08:24:16 UTC 2020 : Received response. Status: 200, Integration latency: 3790 ms
Fri Nov 06 08:24:16 UTC 2020 : Endpoint response headers: {Date=Fri, 06 Nov 2020 08:24:16 GMT, Content-Type=application/json, Content-Length=114, Connection=keep-alive, x-amzn-RequestId=61084a70-8bac-4813-a0a1-7b373ff3c645, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5fa5082c-b22213146173f6ac3d6f0a78;sampled=0}
Fri Nov 06 08:24:16 UTC 2020 : Endpoint response body before transformations: {"errorMessage":"2020-11-06T08:24:16.742Z 61084a70-8bac-4813-a0a1-7b373ff3c645 Task timed out after 3.14 seconds"}
Fri Nov 06 08:24:16 UTC 2020 : Lambda execution failed with status 200 due to customer function error: 2020-11-06T08:24:16.742Z 61084a70-8bac-4813-a0a1-7b373ff3c645 Task timed out after 3.14 seconds. Lambda request id: 61084a70-8bac-4813-a0a1-7b373ff3c645
Fri Nov 06 08:24:16 UTC 2020 : Method completed with status: 502

This is an error I get for an update method using PATCH Variable:

status: 500 Internal Server Error

Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.

My log result for update method:

Execution log for request e4659179-42c0-477f-9319-990255d1b1df
Fri Nov 06 08:30:03 UTC 2020 : Starting execution for request: e4659179-42c0-477f-9319-990255d1b1df
Fri Nov 06 08:30:03 UTC 2020 : HTTP Method: PATCH, Resource Path: /items/27
Fri Nov 06 08:30:03 UTC 2020 : Method request path: {id=27}
Fri Nov 06 08:30:03 UTC 2020 : Method request query string: {}
Fri Nov 06 08:30:03 UTC 2020 : Method request headers: {}
Fri Nov 06 08:30:03 UTC 2020 : Method request body before transformations: {
    name: "preethi"
}
Fri Nov 06 08:30:03 UTC 2020 : Endpoint request URI: https://lambda.ap-south-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-south-1:146331168322:function:ApiLambdaCrudDynamoDBExam-updateItemFunction594152-1NPGGL1HKFE40/invocations
Fri Nov 06 08:30:03 UTC 2020 : Endpoint request headers: {x-amzn-lambda-integration-tag=e4659179-42c0-477f-9319-990255d1b1df, Authorization=*************************************************************************************************************************************************************************************************************************************************************************************************************************6d6efa, X-Amz-Date=20201106T083003Z, x-amzn-apigateway-api-id=uqsoztcq5a, X-Amz-Source-Arn=arn:aws:execute-api:ap-south-1:146331168322:uqsoztcq5a/test-invoke-stage/PATCH/items/{id}, Accept=application/json, User-Agent=AmazonAPIGateway_uqsoztcq5a, X-Amz-Security-Token=IQoJb3JpZ2luX2VjEKj//////////wEaCmFwLXNvdXRoLTEiRzBFAiEAvmG/8/7fAIU+73KrPFG0R6u/ZcbXNDx190rRDx6y/EYCIBxs5CaMP4s23gbV1MGKgRYUpzDZsVq91o3i4xNVeJG3KrYDCBAQAhoMNTA3MDY5NzE3ODU1IgzKI1y59wuz3H7fuusqkwNszL0Rq8nPVll3N7BioaKqJ4g9GMh2F1DMr+AMDPtIE4Lb66I5/eagM/Yjj7Kj0dEIqbQQBuUroMJ5zkKoY0NPciAl2ziBR3gNG53o4Ty54Ko6G4Wgy4yCB9oHO/lOzvILwCy7+1xUdM [TRUNCATED]
Fri Nov 06 08:30:03 UTC 2020 : Endpoint request body after transformations: {"resource":"/items/{id}","path":"/items/27","httpMethod":"PATCH","headers":null,"multiValueHeaders":null,"queryStringParameters":null,"multiValueQueryStringParameters":null,"pathParameters":{"id":"27"},"stageVariables":null,"requestContext":{"resourceId":"f9jcg9","resourcePath":"/items/{id}","httpMethod":"PATCH","extendedRequestId":"Vk5tvExFBcwFkaQ=","requestTime":"06/Nov/2020:08:30:03 +0000","path":"/items/{id}","accountId":"146331168322","protocol":"HTTP/1.1","stage":"test-invoke-stage","domainPrefix":"testPrefix","requestTimeEpoch":1604651403086,"requestId":"e4659179-42c0-477f-9319-990255d1b1df","identity":{"cognitoIdentityPoolId":null,"cognitoIdentityId":null,"apiKey":"test-invoke-api-key","principalOrgId":null,"cognitoAuthenticationType":null,"userArn":"arn:aws:iam::146331168322:root","apiKeyId":"test-invoke-api-key-id","userAgent":"aws-internal/3 aws-sdk-java/1.11.848 Linux/4.9.217-0.3.ac.206.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.262-b10 java/1.8. [TRUNCATED]
Fri Nov 06 08:30:03 UTC 2020 : Sending request to https://lambda.ap-south-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-south-1:146331168322:function:ApiLambdaCrudDynamoDBExam-updateItemFunction594152-1NPGGL1HKFE40/invocations
Fri Nov 06 08:30:03 UTC 2020 : Received response. Status: 200, Integration latency: 658 ms
Fri Nov 06 08:30:03 UTC 2020 : Endpoint response headers: {Date=Fri, 06 Nov 2020 08:30:03 GMT, Content-Type=application/json, Content-Length=310, Connection=keep-alive, x-amzn-RequestId=1b712e13-9d8b-4130-b4c0-1e61a2c62199, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5fa5098b-0aed1456c9bedb06759501de;sampled=0}
Fri Nov 06 08:30:03 UTC 2020 : Endpoint response body before transformations: {"errorType":"SyntaxError","errorMessage":"Unexpected token n in JSON at position 6","trace":["SyntaxError: Unexpected token n in JSON at position 6","    at JSON.parse (<anonymous>)","    at Runtime.exports.handler (/var/task/update-one.js:16:74)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}
Fri Nov 06 08:30:03 UTC 2020 : Lambda execution failed with status 200 due to customer function error: Unexpected token n in JSON at position 6. Lambda request id: 1b712e13-9d8b-4130-b4c0-1e61a2c62199
Fri Nov 06 08:30:03 UTC 2020 : Method completed with status: 502

please help me to resolve it.

@SomayaB SomayaB added bug This issue is a bug. language/typescript Related to Typescript examples needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2020
@NGL321 NGL321 added effort/medium Medium work item – a couple days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels May 17, 2021
@mergify mergify bot closed this as completed in #468 Jul 10, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort language/typescript Related to Typescript examples p2
Projects
None yet
3 participants