11

I'm trying to set path parameters when making calls to API Gateway endpoints via the JavaScript SDK and not having any luck. It looks like I either have something misconfigured or there is a bug in the SDK generation.

I am able to successfully call endpoints that do not take path parameters but when I try to pass in a parameter to be used as a path parameter the SDK just replaces the path parameter with a blank and my call fails.

Example, assume client is a properly initialized API Gateway client. I have an endpoint called /measurement with a child of /measurement/{id}. I am able to call both directly.

client.measurementGet({},{}); - successfully calls my /measurement endpoint client.measurementIdGet({"id": "1234"}, {}); - Browser makes a call to /measurement/ instead of /measurement/1234

Looking at the source of my apigClient.js, it appears that the SDK generator is not putting path parameters into the list of parameters that it's looking for. For example, the code of my generated measurementIdGet method looks like this:

    apigClient.measurementIdGet = function (params, body, additionalParams) {
        if(additionalParams === undefined) { additionalParams = {}; }

        apiGateway.core.utils.assertParametersDefined(params, [], ['body']);

        var measurementIdGetRequest = {
            verb: 'get'.toUpperCase(),
            path: pathComponent + uritemplate('/measurement/{id}').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
            headers: apiGateway.core.utils.parseParametersToObject(params, []),
            queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
            body: body
        };

        return apiGatewayClient.makeRequest(measurementIdGetRequest, authType, additionalParams, config.apiKey);
    };

I dug into the assertParametersDefined and parseParametersToObject and it looks like those methods are expecting a list of parameters to look for. In both cases the SDK has generated empty lists instead of putting my path parameter in there.

If I manually update the generated file to change the two lines to

apiGateway.core.utils.assertParametersDefined(params, ['id'], ['body']);

and

apiGateway.core.utils.parseParametersToObject(params, ['id'])

The SDK makes the proper call.

Am I missing something in my configuration or is there a bug in the code generator?

3
  • 1
    I have this same issue here. any update on this? @mason Commented Apr 27, 2016 at 18:37
  • Same issue for me. I asked about it on the forum and haven't gotten any answer: forums.aws.amazon.com/thread.jspa?messageID=734395. Anyone know if the SDK generator is open source? Couldn't find it anywhere Commented Aug 5, 2016 at 14:17
  • Sorry to bug but any update here ? Still getting this issue Commented Jan 26, 2017 at 15:22

4 Answers 4

2

If you are using cloud formation like me. You will need to add it in the RequestParameters.

for a resource like this /api/pets/{id}/attributes/{attrid} following code works

  PetsByIdAttributesByAttridGetMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      RestApiId: !Ref MyApi
      ResourceId: !Ref PetsByIdAttributesByAttridResource
      HttpMethod: GET
      AuthorizationType: AWS_IAM
      RequestParameters:
        method.request.path.id : true
        method.request.path.attrid : true
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambda.Arn}/invocations
Sign up to request clarification or add additional context in comments.

Comments

1

I know it's an old question, but for those new to AWS that may still run into this issue like I did, I hope this answer helps:

In the AWS API Gateway Console, make sure that you specify the "URL Query String Parameters" in the "Method Request" for your "GET". Then re-deploy your API and generate the SDK again. This time the apigClient.js will be generated with the defined Query Parameter keys correctly filled in to the calls to assertParametersDefined and parseParametersToObject.

API Gateway Console where you define Query Parameters

Comments

0

Assuming that you're importing a swagger definition to create the API, defining your parameters at the method level as opposed to the path level will result in a generated SDK with the key filled out and should work correctly.

{
    ...
    "/path/{to}/resource": {
        "get": {
            "parameters": [ // define here
                "name": "to",
                "in": "path",
                ...
            ],
            ...
        },
        "parameters": [] // not here
}

Although defining parameters at the path level is correct according the the Swagger spec and API Gateway does use them in the created API, it appears that API Gateway disregards them in some contexts.

Comments

0

This look's like an issue doesn't parse the params.

https://github.com/aws/chalice/issues/498enter link description here

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.