-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Hello,
I recently had to add caching properties to the application, so I added stage and deployment resources my template.
However, no matter what I try I can't get the result I want.
Defining Api.StageName dynamically via a parameter gives me "DuplicateLogicalIdException". I have read about that and since this isn't a must for me I hardcoded it (see below).
That produced two stages / deployments and, more importantly, the one I named "v1" in my "Api" resource didn't have caching enabled for it by default (obviously).
So, I went ahead and added a ApiStage.StageName property and set it to "v1" renaming the original one to "extra" and that worked fine.
My question is: Is there a way for AWS::ApiGateway::Deployment, AWS::ApiGateway::Stage, AWS::Serverless::Api (with OpenAPI) to co-exist in one template without anything being duplicated upon deployment?
Basically this is what I'm after in my CF stack (logical IDs below):
- Api
- ApiDeployment
- ApiStage (a single one with (/v1 path prefix)
Failing that, can I enable stage caching without defining a AWS::ApiGateway::Stage in my SAM template?
I could only find path parameter cache settings I can set in openapi.yaml, nothing on global, stage ones.
Relevant portions of working template below. The full version is larger, with additional AWS::Serverless::Function, AWS::Serverless::LayerVersion, AWS::IAM::Role resources.
Globals:
Api:
OpenApiVersion: 3.0.1
ApiDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref Api
ApiStage:
Type: AWS::ApiGateway::Stage
Properties:
CacheClusterEnabled: true
CacheClusterSize: 0.5
DeploymentId: !Ref ApiDeployment
RestApiId: !Ref Api
StageName: v1
Api:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: openapi.yaml
StageName: extra (original version had !Ref ParamStageName)
Thank you.