Bug Report
If using AWS::ApiGateway::ApiKey Resource in serverless.yml,
I cannot deploy multipile stage.
service: example-api
provider:
name: aws
runtime: nodejs4.3
stage: prod
region: us-east-1
apiKeys:
- exampleKey
functions:
exampleKey:
handler: index.handler
description: Example api
events:
- http:
path: example/{post_id}
method: get
private: true
1st deploy is success.
$ sls deploy -s prod
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.................................
Serverless: Stack update finished...
Service Information
service: example-api
stage: prod
region: us-east-1
api keys:
exampleKey: o5jil98nb4
endpoints:
GET - https://xxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/example/{post_id}
functions:
example-api-prod-exampleKey: arn:aws:lambda:us-east-1:610511741716:function:example-api-prod-cloudfron
tTransaction
But if I try to deploy another stages, deployment is failed.
$ sls deploy -s dev
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
....................................................Serverless: Deployment failed!
Serverless Error ---------------------------------------
An error occurred while provisioning your stack: ApiGatewayApiKey1
- exampleKey already exists in stack arn:aws:cloudformation:us-east-1:9999999999:stack/example-api-dev/3d0254
a0-890a-11e6-9009-50d5ca632682.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
% node -v
v6.7.0
% sls -v
1.0.0-rc.2
I think AWS::ApiGateway::ApiKey need some prefix like prod-exampleKey and dev-exampleKey.
And can I try to add those code in following space ?
https://github.com/serverless/serverless/blob/e1adf6e921aba5588ba85f3d5cd0ba4158cd4a35/lib/plugins/aws/deploy/compile/events/apiGateway/lib/apiKeys.js#L25
thanks !
Why not use ${opt:stage} variable?
https://github.com/serverless/serverless/blob/master/docs/01-guide/08-serverless-variables.md#referencing-cli-options
apiKeys:
- ${opt:stage}-example-key