diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index fe6d139b63..204f180c7a 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -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) @@ -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: diff --git a/tests/translator/output/aws-cn/api_with_usageplans.json b/tests/translator/output/aws-cn/api_with_usageplans.json index 3f38b0ce5e..7f3fe62693 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans.json +++ b/tests/translator/output/aws-cn/api_with_usageplans.json @@ -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" @@ -399,8 +383,6 @@ ] }, "DependsOn": [ - "MyApiThree", - "ServerlessRestApi", "MyApiThree", "ServerlessRestApi" ] @@ -601,22 +583,6 @@ "Properties": { "Enabled": true, "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": { - "Ref": "MyApiThreeProdStage" - } - }, - { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": { - "Ref": "ServerlessRestApiProdStage" - } - }, { "RestApiId": { "Ref": "MyApiThree" diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans.json b/tests/translator/output/aws-us-gov/api_with_usageplans.json index 7c0d0eaad3..8309958bab 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans.json @@ -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" @@ -414,10 +382,6 @@ ] }, "DependsOn": [ - "MyApiThree", - "ServerlessRestApi", - "MyApiThree", - "ServerlessRestApi", "MyApiThree", "ServerlessRestApi" ] @@ -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"