Skip to content

Commit 1350915

Browse files
authored
fix: Add MergeDefinitions property to Global Section (#2976)
1 parent 4d00cff commit 1350915

File tree

6 files changed

+613
-2
lines changed

6 files changed

+613
-2
lines changed

samtranslator/plugins/globals/globals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Globals:
6262
"DefinitionUri",
6363
"CacheClusterEnabled",
6464
"CacheClusterSize",
65+
"MergeDefinitions",
6566
"Variables",
6667
"EndpointConfiguration",
6768
"MethodSettings",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Transform: AWS::Serverless-2016-10-31
2+
3+
Globals:
4+
Api:
5+
MergeDefinitions: true
6+
7+
Resources:
8+
MyApi:
9+
Type: AWS::Serverless::Api
10+
Properties:
11+
StageName: Prod
12+
DefinitionBody:
13+
swagger: '2.0'
14+
info:
15+
title: Example
16+
version: '1'
17+
paths:
18+
/test:
19+
get:
20+
security:
21+
MyAuthorizer2: []
22+
Auth:
23+
Authorizers:
24+
MyAuthorizer:
25+
UserPoolArn: !GetAtt MyCognitoUserPool.Arn
26+
27+
MyAuthorizer2:
28+
UserPoolArn: !GetAtt MyCognitoUserPool2.Arn
29+
30+
MyFunction:
31+
Type: AWS::Serverless::Function
32+
Properties:
33+
Handler: index.handler
34+
Runtime: nodejs14.x
35+
InlineCode: |
36+
exports.handler = async (event, context, callback) => {
37+
return {
38+
statusCode: 200,
39+
body: 'Success'
40+
}
41+
}
42+
Events:
43+
MyEventV1:
44+
Type: Api
45+
Properties:
46+
RestApiId: !Ref MyApi
47+
Path: /test
48+
Method: get
49+
Auth:
50+
Authorizer: MyAuthorizer
51+
52+
MyCognitoUserPool:
53+
Type: AWS::Cognito::UserPool
54+
Properties:
55+
UserPoolName: MyCognitoUserPoolRandomName
56+
57+
MyCognitoUserPool2:
58+
Type: AWS::Cognito::UserPool
59+
Properties:
60+
UserPoolName: MyCognitoUserPoolRandomName2
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"Resources": {
3+
"MyApi": {
4+
"Properties": {
5+
"Body": {
6+
"info": {
7+
"title": "Example",
8+
"version": "1"
9+
},
10+
"paths": {
11+
"/test": {
12+
"get": {
13+
"responses": {},
14+
"security": [
15+
{
16+
"MyAuthorizer": []
17+
}
18+
],
19+
"x-amazon-apigateway-integration": {
20+
"httpMethod": "POST",
21+
"type": "aws_proxy",
22+
"uri": {
23+
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"securityDefinitions": {
30+
"MyAuthorizer": {
31+
"in": "header",
32+
"name": "Authorization",
33+
"type": "apiKey",
34+
"x-amazon-apigateway-authorizer": {
35+
"providerARNs": [
36+
{
37+
"Fn::GetAtt": [
38+
"MyCognitoUserPool",
39+
"Arn"
40+
]
41+
}
42+
],
43+
"type": "cognito_user_pools"
44+
},
45+
"x-amazon-apigateway-authtype": "cognito_user_pools"
46+
},
47+
"MyAuthorizer2": {
48+
"in": "header",
49+
"name": "Authorization",
50+
"type": "apiKey",
51+
"x-amazon-apigateway-authorizer": {
52+
"providerARNs": [
53+
{
54+
"Fn::GetAtt": [
55+
"MyCognitoUserPool2",
56+
"Arn"
57+
]
58+
}
59+
],
60+
"type": "cognito_user_pools"
61+
},
62+
"x-amazon-apigateway-authtype": "cognito_user_pools"
63+
}
64+
},
65+
"swagger": "2.0"
66+
}
67+
},
68+
"Type": "AWS::ApiGateway::RestApi"
69+
},
70+
"MyApiDeploymentf4bf62db4c": {
71+
"Properties": {
72+
"Description": "RestApi deployment id: f4bf62db4c8bd0cbd8276f47c4280a81f4adec16",
73+
"RestApiId": {
74+
"Ref": "MyApi"
75+
},
76+
"StageName": "Stage"
77+
},
78+
"Type": "AWS::ApiGateway::Deployment"
79+
},
80+
"MyApiProdStage": {
81+
"Properties": {
82+
"DeploymentId": {
83+
"Ref": "MyApiDeploymentf4bf62db4c"
84+
},
85+
"RestApiId": {
86+
"Ref": "MyApi"
87+
},
88+
"StageName": "Prod"
89+
},
90+
"Type": "AWS::ApiGateway::Stage"
91+
},
92+
"MyCognitoUserPool": {
93+
"Properties": {
94+
"UserPoolName": "MyCognitoUserPoolRandomName"
95+
},
96+
"Type": "AWS::Cognito::UserPool"
97+
},
98+
"MyCognitoUserPool2": {
99+
"Properties": {
100+
"UserPoolName": "MyCognitoUserPoolRandomName2"
101+
},
102+
"Type": "AWS::Cognito::UserPool"
103+
},
104+
"MyFunction": {
105+
"Properties": {
106+
"Code": {
107+
"ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n"
108+
},
109+
"Handler": "index.handler",
110+
"Role": {
111+
"Fn::GetAtt": [
112+
"MyFunctionRole",
113+
"Arn"
114+
]
115+
},
116+
"Runtime": "nodejs14.x",
117+
"Tags": [
118+
{
119+
"Key": "lambda:createdBy",
120+
"Value": "SAM"
121+
}
122+
]
123+
},
124+
"Type": "AWS::Lambda::Function"
125+
},
126+
"MyFunctionMyEventV1PermissionProd": {
127+
"Properties": {
128+
"Action": "lambda:InvokeFunction",
129+
"FunctionName": {
130+
"Ref": "MyFunction"
131+
},
132+
"Principal": "apigateway.amazonaws.com",
133+
"SourceArn": {
134+
"Fn::Sub": [
135+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/test",
136+
{
137+
"__ApiId__": {
138+
"Ref": "MyApi"
139+
},
140+
"__Stage__": "*"
141+
}
142+
]
143+
}
144+
},
145+
"Type": "AWS::Lambda::Permission"
146+
},
147+
"MyFunctionRole": {
148+
"Properties": {
149+
"AssumeRolePolicyDocument": {
150+
"Statement": [
151+
{
152+
"Action": [
153+
"sts:AssumeRole"
154+
],
155+
"Effect": "Allow",
156+
"Principal": {
157+
"Service": [
158+
"lambda.amazonaws.com"
159+
]
160+
}
161+
}
162+
],
163+
"Version": "2012-10-17"
164+
},
165+
"ManagedPolicyArns": [
166+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
167+
],
168+
"Tags": [
169+
{
170+
"Key": "lambda:createdBy",
171+
"Value": "SAM"
172+
}
173+
]
174+
},
175+
"Type": "AWS::IAM::Role"
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)