Skip to content

Commit

Permalink
fix: Availability Dip Fix for MergeDefinitions property (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinZZ committed Apr 17, 2023
1 parent 9e594d4 commit 2876cbd
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def _get_merged_definitions(
- otherwise include key-value pairs from both definitions
"""
merged_definition_body = source_definition_body.copy()
source_body_paths = merged_definition_body.get("paths", {})
source_body_paths = merged_definition_body.get("paths") or {}

try:
path_method_body = dict_deep_get(source_body_paths, [self.Path, self.Method]) or {}
Expand Down
26 changes: 26 additions & 0 deletions tests/translator/input/api_with_merge_definitions_null_paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Resources:
WebhooksApi:
Type: AWS::Serverless::Api
Properties:
StageName: live
MergeDefinitions: true
DefinitionBody:
swagger: 2
paths:
x-amazon-apigateway-policy:
Version: '2012-10-17'


WebhooksReceiver:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://bucket/key
Handler: code/handler
Runtime: python3.8
Events:
AllEvent:
Type: Api
Properties:
RestApiId: !Ref WebhooksApi
Path: /proxy
Method: any
112 changes: 112 additions & 0 deletions tests/translator/output/api_with_merge_definitions_null_paths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"Resources": {
"WebhooksApi": {
"Properties": {
"Body": {
"paths": null,
"swagger": 2,
"x-amazon-apigateway-policy": {
"Version": "2012-10-17"
}
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"WebhooksApiDeployment5ce813cc52": {
"Properties": {
"Description": "RestApi deployment id: 5ce813cc52a4e5d017317029559e0c18939085eb",
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"WebhooksApiliveStage": {
"Properties": {
"DeploymentId": {
"Ref": "WebhooksApiDeployment5ce813cc52"
},
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "live"
},
"Type": "AWS::ApiGateway::Stage"
},
"WebhooksReceiver": {
"Properties": {
"Code": {
"S3Bucket": "bucket",
"S3Key": "key"
},
"Handler": "code/handler",
"Role": {
"Fn::GetAtt": [
"WebhooksReceiverRole",
"Arn"
]
},
"Runtime": "python3.8",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"WebhooksReceiverAllEventPermissionlive": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebhooksReceiver"
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/proxy",
{
"__ApiId__": {
"Ref": "WebhooksApi"
},
"__Stage__": "*"
}
]
}
},
"Type": "AWS::Lambda::Permission"
},
"WebhooksReceiverRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"Resources": {
"WebhooksApi": {
"Properties": {
"Body": {
"paths": null,
"swagger": 2,
"x-amazon-apigateway-policy": {
"Version": "2012-10-17"
}
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
]
},
"Parameters": {
"endpointConfigurationTypes": "REGIONAL"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"WebhooksApiDeployment5ce813cc52": {
"Properties": {
"Description": "RestApi deployment id: 5ce813cc52a4e5d017317029559e0c18939085eb",
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"WebhooksApiliveStage": {
"Properties": {
"DeploymentId": {
"Ref": "WebhooksApiDeployment5ce813cc52"
},
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "live"
},
"Type": "AWS::ApiGateway::Stage"
},
"WebhooksReceiver": {
"Properties": {
"Code": {
"S3Bucket": "bucket",
"S3Key": "key"
},
"Handler": "code/handler",
"Role": {
"Fn::GetAtt": [
"WebhooksReceiverRole",
"Arn"
]
},
"Runtime": "python3.8",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"WebhooksReceiverAllEventPermissionlive": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebhooksReceiver"
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": [
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/proxy",
{
"__ApiId__": {
"Ref": "WebhooksApi"
},
"__Stage__": "*"
}
]
}
},
"Type": "AWS::Lambda::Permission"
},
"WebhooksReceiverRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"Resources": {
"WebhooksApi": {
"Properties": {
"Body": {
"paths": null,
"swagger": 2,
"x-amazon-apigateway-policy": {
"Version": "2012-10-17"
}
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
]
},
"Parameters": {
"endpointConfigurationTypes": "REGIONAL"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"WebhooksApiDeployment5ce813cc52": {
"Properties": {
"Description": "RestApi deployment id: 5ce813cc52a4e5d017317029559e0c18939085eb",
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"WebhooksApiliveStage": {
"Properties": {
"DeploymentId": {
"Ref": "WebhooksApiDeployment5ce813cc52"
},
"RestApiId": {
"Ref": "WebhooksApi"
},
"StageName": "live"
},
"Type": "AWS::ApiGateway::Stage"
},
"WebhooksReceiver": {
"Properties": {
"Code": {
"S3Bucket": "bucket",
"S3Key": "key"
},
"Handler": "code/handler",
"Role": {
"Fn::GetAtt": [
"WebhooksReceiverRole",
"Arn"
]
},
"Runtime": "python3.8",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"WebhooksReceiverAllEventPermissionlive": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebhooksReceiver"
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": [
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/proxy",
{
"__ApiId__": {
"Ref": "WebhooksApi"
},
"__Stage__": "*"
}
]
}
},
"Type": "AWS::Lambda::Permission"
},
"WebhooksReceiverRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::IAM::Role"
}
}
}

0 comments on commit 2876cbd

Please sign in to comment.