-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Hey Guys,
I have the following SAM configuration, which works quite well so far:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: "Fancy Description"
Mappings:
Constants:
ServerlessService:
Version: 0.0.1
Globals:
# Sets global settings for ALL Lambda functions
Function:
Runtime: nodejs6.10
Timeout: 30
Handler: index.handle
Resources:
ServerlessService:
Type: AWS::Serverless::Api
Properties:
StageName: test
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: s3://<ServerlessService-S3-Bucket>/swagger.yml
ServerlessServiceDefaultUsagePlan:
Type: AWS::ApiGateway::UsagePlan
DependsOn: ServerlessServicetestStage
Properties:
ApiStages:
- ApiId: !Ref ServerlessService
Stage: test
Description: Default Serverless-Service Usage Plan
Quota:
Limit: 5000
Period: MONTH
Throttle:
BurstLimit: 40
RateLimit: 20
UsagePlanName: serverless-service-default-plan
ServerlessServiceFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ../packages/lambda/functions/serverlessServiceFunction
Events:
ProxyApiRoot:
Type: Api
Properties:
RestApiId: !Ref ServerlessService
Path: /path/with/{params}
Method: POST
Please notice, that its only working, because I'm using the undocumented "feature" (or should I say hack?) as recommended here.
So have a closer look at this part:
ServerlessServiceDefaultUsagePlan:
Type: AWS::ApiGateway::UsagePlan
DependsOn: ServerlessServicetestStage
Properties:
...
Note, that the Resource ServerlessServicetestStage
seems to be newly created by SAM (or what ever) and is never specified in the yaml file. Its very unintuitive to come up with this Resource name! Its really not nice, but as long as it works I don't complain.
But here is my issue: as I want to make the stage test
at least a bit more flexible I tried to utilize the !Join
intrinsic function.
ServerlessServiceDefaultUsagePlan:
Type: AWS::ApiGateway::UsagePlan
DependsOn: !Join
- ''
- - 'ServerlessService'
- 'test'
- 'Stage'
Properties:
...
Which fails with
Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure
state Status: FAILED. Reason: Template format error: DependsOn must be a string or list of strings.
The ultimate goal is to achieve this:
ServerlessServiceDefaultUsagePlan:
Type: AWS::ApiGateway::UsagePlan
DependsOn: !Join
- ''
- - 'ServerlessService'
- !Sub ${StageName}
- 'Stage'
Properties:
...
It seems that !Join
does not work on DependsOn
.
I have the feeling that I'm failing to do a dirty workaround of an even dirtier workaround. What am I missing? What is the cleanest way to have a parameter like this:
Parameters:
StageName:
Description: API Stage Name
Type: String
Default: test
And use !Sub ${StageName}
where a Stage Name is needed?
I read #32 and #97. Both got closed without a proper solution of the issue that a UsagePlan is depending on an APIGateway. Help is very appreciated.