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
4 changes: 3 additions & 1 deletion samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,9 @@ def _add_custom_statement(self, custom_statements):
statement = self.resource_policy['Statement']
if not isinstance(statement, list):
statement = [statement]
statement.extend(custom_statements)
for s in custom_statements:
if s not in statement:
statement.append(s)
self.resource_policy['Statement'] = statement

def add_request_parameters_to_method(self, path, method_name, request_parameters):
Expand Down
16 changes: 15 additions & 1 deletion tests/translator/input/api_with_resource_policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ Resources:
Properties:
RestApiId:
Ref: ExplicitApi
Path: /
Path: /one
Method: get
PostHtml:
Type: Api
Properties:
RestApiId:
Ref: ExplicitApi
Path: /two
Method: post
PutHtml:
Type: Api
Properties:
RestApiId:
Ref: ExplicitApi
Path: /three
Method: put


92 changes: 79 additions & 13 deletions tests/translator/output/api_with_resource_policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@
]
}
},
"ExplicitApiDeploymentd2036decb3": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: d2036decb36ce147b7738a97c419737ea7e02555",
"StageName": "Stage"
}
},
"ExplicitApiFunctionPutHtmlPermissionProd": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "ExplicitApiFunction"
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "ExplicitApi"
}
}
]
}
}
},
"ExplicitApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand All @@ -34,7 +65,7 @@
}
},
"paths": {
"/": {
"/one": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
Expand All @@ -45,6 +76,30 @@
},
"responses": {}
}
},
"/three": {
"put": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
}
},
"/two": {
"post": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
}
}
},
"swagger": "2.0",
Expand All @@ -62,28 +117,39 @@
}
}
},
"ExplicitApiDeploymentcdee3f2ed1": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: cdee3f2ed1733103d54a04f635e1acc120e714c1",
"StageName": "Stage"
}
},
"ExplicitApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiDeploymentcdee3f2ed1"
"Ref": "ExplicitApiDeploymentd2036decb3"
},
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Prod"
}
},
"ExplicitApiFunctionPostHtmlPermissionProd": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "ExplicitApiFunction"
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "ExplicitApi"
}
}
]
}
}
},
"ExplicitApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -118,7 +184,7 @@
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/",
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/one",
{
"__Stage__": "*",
"__ApiId__": {
Expand Down
92 changes: 79 additions & 13 deletions tests/translator/output/aws-cn/api_with_resource_policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@
]
}
},
"ExplicitApiFunctionPutHtmlPermissionProd": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "ExplicitApiFunction"
},
"SourceArn": {
"Fn::Sub": [
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "ExplicitApi"
}
}
]
}
}
},
"ExplicitApiDeployment09f793ab58": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: 09f793ab583fe684660829cf209f0e28340df577",
"StageName": "Stage"
}
},
"ExplicitApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand All @@ -34,7 +65,7 @@
}
},
"paths": {
"/": {
"/one": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
Expand All @@ -45,6 +76,30 @@
},
"responses": {}
}
},
"/three": {
"put": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
}
},
"/two": {
"post": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations"
}
},
"responses": {}
}
}
},
"swagger": "2.0",
Expand Down Expand Up @@ -74,14 +129,35 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiDeployment3f65c799d9"
"Ref": "ExplicitApiDeployment09f793ab58"
},
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Prod"
}
},
"ExplicitApiFunctionPostHtmlPermissionProd": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:invokeFunction",
"Principal": "apigateway.amazonaws.com",
"FunctionName": {
"Ref": "ExplicitApiFunction"
},
"SourceArn": {
"Fn::Sub": [
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two",
{
"__Stage__": "*",
"__ApiId__": {
"Ref": "ExplicitApi"
}
}
]
}
}
},
"ExplicitApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -116,7 +192,7 @@
},
"SourceArn": {
"Fn::Sub": [
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/",
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/one",
{
"__Stage__": "*",
"__ApiId__": {
Expand All @@ -126,16 +202,6 @@
]
}
}
},
"ExplicitApiDeployment3f65c799d9": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ExplicitApi"
},
"Description": "RestApi deployment id: 3f65c799d9b1cd1ec9957134eb76169e7d79d54b",
"StageName": "Stage"
}
}
}
}
Loading