Home > front end >  How to pass path parameters to JSON used for AWS Lambda Invocation?
How to pass path parameters to JSON used for AWS Lambda Invocation?

Time:11-02

I'm trying to invoke AWS Lambda via Java to call my REST API using a JSON file. The JSON file looks like this:

{
  "httpMethod": "PUT",
  "headers": {
    "accept": "application/json"
  },
  "path": "/some-api/v1/channels/company/employees/{id}",
  "pathParameters": {
    "id": "%s"
  },
  "body" : "{\"name\": \"Jeff\", \"language\": \"en-US\", \"job\": {\"location\": \"NYC\", \"jobCode\": \"0000\"}}",
  "isBase64Encoded": false
}

The {id} in the path is supposed to get replaced with the id that is in the pathParameters. I can see the id in pathParameters gets replaced when AWS Lambda is invoked but not the {id} in the actual path. This throws an illegal character argument exception as the {} are not being filled when calling my API. What do I have to change here?

NOTE: I am NOT using API Gateway so please don't suggest mapping or anything I have to do in the UI unless it can be done in the JSON itsef...

CodePudding user response:

Looks like pathParameters only responds to the resource tag. I fixed this by adding %s to the end of the path. :

{
  "httpMethod": "PUT",
  "headers": {
    "accept": "application/json"
  },
  "path": "/some-api/v1/channels/company/employees/%s",
  "body" : "{\"name\": \"Jeff\", \"language\": \"en-US\", \"job\": {\"location\": \"NYC\", \"jobCode\": \"0000\"}}",
  "isBase64Encoded": false
}

Thanks for your shitty documentation, AWS.

  • Related