serverless-apigw-binary icon indicating copy to clipboard operation
serverless-apigw-binary copied to clipboard

Ask for ApiGatewayRestApi directly

Open labichn opened this issue 6 years ago • 4 comments

The function (getApiId) assumes that there exists some Output in every Stack with an OutputKey that matches 'ServiceEndpoint', but this is not always the case. (See #49, #50, #51.)

This PR modifies getApiId to request the ApiGatewayRestApi directly, rather than searching for and parsing the ServiceEndpoint. In the case where no ApiGatewayRestApi exists the plugin will have no effect, as expected.

labichn avatar Apr 26 '19 20:04 labichn

@labichn Can you confirm this works with shared API Gateways too, when this plugin is used in an service which is using

provider:
  apiGateway:
    restApiId: xxxxx
    restApiRootResourceId: xxxx

QuingKhaos avatar May 06 '19 12:05 QuingKhaos

@EmiiKhaos I'm not familiar with that feature, but at a glance it seems to share a single ApiGatewayRestApi value among multiple stacks. If each stack has a resource named ApiGatewayRestApi this change will work.

You can confirm this yourself by looking at the stack resources on CloudFormation--if there is a resource with the key ApiGatewayRestApi, then shared gateways are also supported by this PR.

labichn avatar May 06 '19 16:05 labichn

@labichn No, services using shared ApiGateway do not have ApiGatewayRestApi resource. They are just referencing an id exported by another cloud formation stack. So, no, this won't work with shared ApiGateway.

hakimio avatar Oct 02 '19 06:10 hakimio

I am having this problem too. aws cloudformation describe-stacks reports both ServiceEndpoint and ServiceEndpointWebsocket and getApiId chokes on the latter's OutputValue of 'wss://...' This fix solves the problem @maciejtreder

[ { OutputKey: 'ServiceEndpoint', OutputValue: 'https://ayo7ickqe8.execute-api.us-east-2.amazonaws.com/dev', Description: 'URL of the service endpoint' }, { OutputKey: 'ServiceEndpointWebsocket', OutputValue: 'wss://2nraf1ssae.execute-api.us-east-2.amazonaws.com/dev', Description: 'URL of the service endpoint' } ]

KenHuffman avatar Aug 18 '20 18:08 KenHuffman