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

ApiGateway.putIntegration cacheKeyParameters required #813

Closed
carlnordenfelt opened this issue Nov 24, 2015 · 6 comments
Closed

ApiGateway.putIntegration cacheKeyParameters required #813

carlnordenfelt opened this issue Nov 24, 2015 · 6 comments

Comments

@carlnordenfelt
Copy link

Hi,

I just invoked the apigateway.putIntegration function and got this error:

{ [TypeError: Cannot read property 'length' of undefined]
   message: 'Cannot read property \'length\' of undefined',
   code: 'TypeError',
  time: Tue Nov 24 2015 09:16:56 GMT+0100 (CET) }

I supplied the four required parameters in this call.

As it turned out I had to supply cacheKeyParameters as an empty array. cacheKeyParameters is not listed as a required parameter.

Regards,
Carl

@carlnordenfelt
Copy link
Author

Noticing a few more things regarding these APIs.

The httpMethod when creating a method is case sensitive and has t be UPPERCASE, i.e. GET, POST etc. There appears to be no validation of this but when invoking a method that was created with lowercase "get" I get an error from API Gateway. This issue is more likely on the API Gateway end of thing and not really related to the JS SDK although it should be reflected in the docs (which I guess is also on the API Gateway team :))

@chrisradek
Copy link
Contributor

@polythene1337
Can you provide more details on what parameters you passed into putIntegration?

I just re-tested putIntegration using the parameters specified in #769 and it succeeds without specifying the cacheKeyParameters parameter.

@carlnordenfelt
Copy link
Author

Hi!

I've tested this a bit more and it turns out that if cacheKeyParameters is provided in params but is either undefined or null it fails. If the key is omitted it works. I would expect that an undefined value would simply be ignored and work just as if the key wasn't provided.

{ httpMethod: 'OPTIONS',
  resourceId: 'xxx',
  restApiId: 'xxx',
  type: 'MOCK',
  cacheKeyParameters: null,
  requestTemplates: { 'application/json': '{"statusCode": 200 }' } }

{ [TypeError: Cannot read property 'length' of null]
  message: 'Cannot read property \'length\' of null',
  code: 'TypeError',
  time: Mon Nov 30 2015 13:43:11 GMT+0100 (CET) }

{ httpMethod: 'OPTIONS',
  resourceId: 'xxx',
  restApiId: 'xxx',
  type: 'MOCK',
  cacheKeyParameters: undefined,
  requestTemplates: { 'application/json': '{"statusCode": 200 }' } }

{ [TypeError: Cannot read property 'length' of undefined]
  message: 'Cannot read property \'length\' of undefined',
  code: 'TypeError',
  time: Mon Nov 30 2015 13:43:11 GMT+0100 (CET) }

@chrisradek
Copy link
Contributor

@polythene1337
This may be partly due to some quirky behavior in JavaScript. Oddly, you can add undefined fields to an object in JavaScript, and that field will then exist and even show up when iterating over all the fields in an object. To truly remove the field, it would have to be deleted using the delete command.

For your use case, would it be possible to prevent setting cacheKeyParameter if the value doesn't exist, or delete it if it has already been set and you want to clear it out?

@carlnordenfelt
Copy link
Author

Hi,

This behaviour is somewhat different from other APIs I've used in the SDK which I would say is about all of them. I've never encountered a case where an undefined key causes an error before.
In this case I'd say that it would make sense for the SDK to check that the key has a valid value before calling length on it.

if (params.cacheKeyParameter) {
     // What ever code is causing the issue
}

That would be the expected behaviour in my opinion.

That said, I've solved it by specifically checking that it is set before adding it to the params.
Thanks for your time and the replies :)

@lock
Copy link

lock bot commented Sep 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants