0

I have a lambda running on AWS that processes a JSON file. I'd like to pass that JSON file from the command line using curl through a REST interface configured on an API gateway, e.g.

curl -X POST -H "x-api-key: MyAPIKey" -H "Content-Type: application/json" -d @myFile.json https://my-api.us-east-1.amazonaws.com/default/MyLambda

I've created an API gateway, and added it as a trigger for the lambda, but when the request method is triggered, the content of the JSON file has been added to the "body" attribute of a JSON object.

Is it possible to pass the file directly to the lambda?

1 Answer 1

1

If you are getting the request in the event.body, it implies that you are using the Lambda Proxy integration.

enter image description here

What you are looking for is known as non-proxy integration or Custom Integration. More details on how to set that up here. Uncheck this option. Then you will have to configure the request and response mapping templates.

If the json looks like the following -

{
  "attr1": "v1",
  "attr2": "v2"
}

then your mapping template for application/json will look like this -

#set($inputRoot = $input.path('$'))
{
  "attr1": "$inputRoot.attr1",
  "attr2": "$inputRoot.attr2",
}

Then in the Lambda function, attributes can directly be accessed as event.attr1, event.attr2 etc.

Then you can use the same cURL command to call the API Gateway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.