Hello,
Thanks a lot for your help in advance.
I create a lambda function call addStock.
If invoke locally it WORKS:
serverless invoke local --function addStock --path mocks/addStock-event.json
but if I use AWS CLI to invoke through API Gateway it is NOT WORKING:
npx aws-api-gateway-cli-test --username=‘sebastian@xxxx’ --password=‘xxxx’ --user-pool-id=‘us-east-1_xxxx’ --app-client-id=‘xxxx’ --cognito-region=‘us-east-1’ --identity-pool-id=‘us-east-1:xxxx’ --invoke-url=‘xxxx.execute-api.us-east-1.amazonawxxxxx/dev’ --api-gateway-region=‘us-east-1’ --path-template=’/portfolios/xxxxx/addStock’ --method=‘PUT’ --body=’{“stockid”: “OPI.US”, “units”: 1, “purchase_price”: 1, “purchase_cost”: 1, “code”: “OPI”, “exchange”: “US”, “name”: “xxxxx”, “country”: “USA”, “currency”: “USD”, “isin”: null}'
Both cases run successfully without return any error.
I checked that the AWS CLI uses the right method (=PUT), and if I return the initial body of the request it is the same for both. The only difference is that the AWS CLI seems to return a nicely formatted JSON, while if it’s invoked locally it returns a string like {“stockid”:“OPI.US”…}.
What makes it even more difficult for me to understand is that both ways the first part of the function is successfully adding the stock the DynamoDB, but the second part which is based on an Axios API call but has no new dependency fails.
How do I best debug this?
What are the differences between the two ways to execute the lambda function?
Thanks a lot,
Sebastian