Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Availability Dip Fix for MergeDefinitions property #3115

Merged
merged 2 commits into from
Apr 17, 2023
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
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
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"
}
}
}