Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,16 @@ def _construct_usage_plan(self, rest_api_stage=None):
# create a usage plan for all the Apis
elif create_usage_plan == "SHARED":
usage_plan_logical_id = "ServerlessUsagePlan"
ApiGenerator.depends_on_shared.append(self.logical_id)
if self.logical_id not in ApiGenerator.depends_on_shared:
ApiGenerator.depends_on_shared.append(self.logical_id)
usage_plan = ApiGatewayUsagePlan(
logical_id=usage_plan_logical_id, depends_on=ApiGenerator.depends_on_shared
)
api_stage = dict()
api_stage["ApiId"] = ref(self.logical_id)
api_stage["Stage"] = ref(rest_api_stage.logical_id)
ApiGenerator.api_stages_shared.append(api_stage)
if api_stage not in ApiGenerator.api_stages_shared:
ApiGenerator.api_stages_shared.append(api_stage)
usage_plan.ApiStages = ApiGenerator.api_stages_shared

api_key = self._construct_api_key(usage_plan_logical_id, create_usage_plan, rest_api_stage)
Expand Down Expand Up @@ -631,7 +633,8 @@ def _construct_api_key(self, usage_plan_logical_id, create_usage_plan, rest_api_
stage_key = dict()
stage_key["RestApiId"] = ref(self.logical_id)
stage_key["StageName"] = ref(rest_api_stage.logical_id)
ApiGenerator.stage_keys_shared.append(stage_key)
if stage_key not in ApiGenerator.stage_keys_shared:
ApiGenerator.stage_keys_shared.append(stage_key)
api_key.StageKeys = ApiGenerator.stage_keys_shared
# for create_usage_plan = "PER_API"
else:
Expand Down
34 changes: 0 additions & 34 deletions tests/translator/output/aws-cn/api_with_usageplans.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,22 +364,6 @@
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "MyApiThree"
},
"Stage": {
"Ref": "MyApiThreeProdStage"
}
},
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"ApiId": {
"Ref": "MyApiThree"
Expand All @@ -399,8 +383,6 @@
]
},
"DependsOn": [
"MyApiThree",
"ServerlessRestApi",
"MyApiThree",
"ServerlessRestApi"
]
Expand Down Expand Up @@ -601,22 +583,6 @@
"Properties": {
"Enabled": true,
"StageKeys": [
{
"RestApiId": {
"Ref": "MyApiThree"
},
"StageName": {
"Ref": "MyApiThreeProdStage"
}
},
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"RestApiId": {
"Ref": "MyApiThree"
Expand Down
68 changes: 0 additions & 68 deletions tests/translator/output/aws-us-gov/api_with_usageplans.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,38 +363,6 @@
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "MyApiThree"
},
"Stage": {
"Ref": "MyApiThreeProdStage"
}
},
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"ApiId": {
"Ref": "MyApiThree"
},
"Stage": {
"Ref": "MyApiThreeProdStage"
}
},
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"ApiId": {
"Ref": "MyApiThree"
Expand All @@ -414,10 +382,6 @@
]
},
"DependsOn": [
"MyApiThree",
"ServerlessRestApi",
"MyApiThree",
"ServerlessRestApi",
"MyApiThree",
"ServerlessRestApi"
]
Expand All @@ -427,38 +391,6 @@
"Properties": {
"Enabled": true,
"StageKeys": [
{
"RestApiId": {
"Ref": "MyApiThree"
},
"StageName": {
"Ref": "MyApiThreeProdStage"
}
},
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"RestApiId": {
"Ref": "MyApiThree"
},
"StageName": {
"Ref": "MyApiThreeProdStage"
}
},
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
},
{
"RestApiId": {
"Ref": "MyApiThree"
Expand Down