maciejtreder / serverless-apigw-binary

Serverless plugin for binary files support in AWS Gateway
MIT License
160 stars 33 forks source link

Ask for ApiGatewayRestApi directly #52

Open labichn opened 5 years ago

labichn commented 5 years ago

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.

QuingKhaos commented 5 years ago

@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
labichn commented 5 years ago

@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.

hakimio commented 5 years ago

@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.

KenHuffman commented 4 years ago

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' } ]