-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
I have a SAM template deploying three resources: An ApiGateway, a Lambda Function and a ApiGateway BasePathMapping.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
StageName:
Type: String
Resources:
api:
Type: AWS::Serverless::Api
Properties:
DefinitionBody: ...
StageName: !Ref StageName
apidomain:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: mydomain.com
RestApiId: !Ref api
Stage: !Ref StageName
lambda:
Type: AWS::Serverless::Function
Properties: ...
There is one parameter to the template called StageName, and this is used in two places:
- The StageName for the ApiGateway
- The Stage value for the BasePathMapping
When this stack is deployed, Cloud Formation deploys things in a strange order. It deploys the Api Gateway before the BasePathMapping, which you would expect, but deploying the ApiGateway stage is a separate step. It tries to deploy the BasePathMapping before the ApiGateway Stage, which results in the error:
Invalid stage identifier specified
This is totally underdtandable given it has not been created yet.
I have tried using the DependsOn property on the BasePathMapping resource to force it to get created after the ApiGateway. It does, but not after the ApiGateway stage.
Does anyone know a way around this? It feels like a bug with the AWS::Serverless::Api resource type. It clearly needs to create a Gateway and a Stage, but the should be done sequentially not not allow the BasePathMapping to be created in between.
Work arounds I don't like include:
- A two stage deployment. First without the BasePathMapping, then with it