Skip to content

Commit 480ce19

Browse files
authored
merge: fix open api set_path_default_authorizer (#2248)
fix: open api set_path_default_authorizer (#2248)
2 parents db25683 + c9ef8d2 commit 480ce19

File tree

6 files changed

+924
-1
lines changed

6 files changed

+924
-1
lines changed

samtranslator/open_api/open_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def set_path_default_authorizer(self, path, default_authorizer, authorizers, api
358358
continue
359359
existing_security = method_definition.get("security", [])
360360
if existing_security:
361-
return
361+
continue
362362
authorizer_list = []
363363
if authorizers:
364364
authorizer_list.extend(authorizers.keys())
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Resources:
2+
HttpApiFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/todo_list.zip
6+
Handler: index.restapi
7+
Runtime: python3.7
8+
Events:
9+
HelloGet:
10+
Type: HttpApi
11+
Properties:
12+
Path: /hello
13+
Method: get
14+
ApiId: !Ref MyApi
15+
HelloPut:
16+
Type: HttpApi
17+
Properties:
18+
Path: /hello
19+
Method: put
20+
ApiId: !Ref MyApi
21+
Auth:
22+
Authorizer: MyOauth2Authorizer
23+
HelloPost:
24+
Type: HttpApi
25+
Properties:
26+
Path: /hello
27+
Method: post
28+
ApiId: !Ref MyApi
29+
SimpleCase: # path exists, integration doesn't
30+
Type: HttpApi
31+
Properties:
32+
ApiId: !Ref MyApi
33+
34+
MyAuthFn:
35+
Type: AWS::Serverless::Function
36+
Properties:
37+
CodeUri: s3://bucket/key
38+
Handler: index.handler
39+
Runtime: nodejs12.x
40+
41+
MyApi:
42+
Type: AWS::Serverless::HttpApi
43+
Properties:
44+
Tags:
45+
Tag1: value1
46+
Tag2: value2
47+
Auth:
48+
Authorizers:
49+
LambdaAuth:
50+
FunctionArn: !GetAtt MyAuthFn.Arn
51+
AuthorizerPayloadFormatVersion: 1.0
52+
MyOauth2Authorizer:
53+
AuthorizationScopes:
54+
- scope
55+
IdentitySource: $request.header.Authorization
56+
JwtConfiguration:
57+
audience:
58+
- audience1
59+
- audience2
60+
issuer: "https://www.example.com/v1/connect/oidc"
61+
DefaultAuthorizer: LambdaAuth
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
{
2+
"Resources": {
3+
"HttpApiFunction": {
4+
"Type": "AWS::Lambda::Function",
5+
"Properties": {
6+
"Code": {
7+
"S3Bucket": "sam-demo-bucket",
8+
"S3Key": "todo_list.zip"
9+
},
10+
"Handler": "index.restapi",
11+
"Role": {
12+
"Fn::GetAtt": [
13+
"HttpApiFunctionRole",
14+
"Arn"
15+
]
16+
},
17+
"Runtime": "python3.7",
18+
"Tags": [
19+
{
20+
"Key": "lambda:createdBy",
21+
"Value": "SAM"
22+
}
23+
]
24+
}
25+
},
26+
"HttpApiFunctionRole": {
27+
"Type": "AWS::IAM::Role",
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Version": "2012-10-17",
31+
"Statement": [
32+
{
33+
"Action": [
34+
"sts:AssumeRole"
35+
],
36+
"Effect": "Allow",
37+
"Principal": {
38+
"Service": [
39+
"lambda.amazonaws.com"
40+
]
41+
}
42+
}
43+
]
44+
},
45+
"ManagedPolicyArns": [
46+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
47+
],
48+
"Tags": [
49+
{
50+
"Key": "lambda:createdBy",
51+
"Value": "SAM"
52+
}
53+
]
54+
}
55+
},
56+
"HttpApiFunctionSimpleCasePermission": {
57+
"Type": "AWS::Lambda::Permission",
58+
"Properties": {
59+
"Action": "lambda:InvokeFunction",
60+
"FunctionName": {
61+
"Ref": "HttpApiFunction"
62+
},
63+
"Principal": "apigateway.amazonaws.com",
64+
"SourceArn": {
65+
"Fn::Sub": [
66+
"arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*",
67+
{
68+
"__ApiId__": {
69+
"Ref": "MyApi"
70+
},
71+
"__Stage__": "*"
72+
}
73+
]
74+
}
75+
}
76+
},
77+
"MyAuthFn": {
78+
"Type": "AWS::Lambda::Function",
79+
"Properties": {
80+
"Code": {
81+
"S3Bucket": "bucket",
82+
"S3Key": "key"
83+
},
84+
"Handler": "index.handler",
85+
"Role": {
86+
"Fn::GetAtt": [
87+
"MyAuthFnRole",
88+
"Arn"
89+
]
90+
},
91+
"Runtime": "nodejs12.x",
92+
"Tags": [
93+
{
94+
"Key": "lambda:createdBy",
95+
"Value": "SAM"
96+
}
97+
]
98+
}
99+
},
100+
"MyAuthFnRole": {
101+
"Type": "AWS::IAM::Role",
102+
"Properties": {
103+
"AssumeRolePolicyDocument": {
104+
"Version": "2012-10-17",
105+
"Statement": [
106+
{
107+
"Action": [
108+
"sts:AssumeRole"
109+
],
110+
"Effect": "Allow",
111+
"Principal": {
112+
"Service": [
113+
"lambda.amazonaws.com"
114+
]
115+
}
116+
}
117+
]
118+
},
119+
"ManagedPolicyArns": [
120+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
121+
],
122+
"Tags": [
123+
{
124+
"Key": "lambda:createdBy",
125+
"Value": "SAM"
126+
}
127+
]
128+
}
129+
},
130+
"MyApi": {
131+
"Type": "AWS::ApiGatewayV2::Api",
132+
"Properties": {
133+
"Body": {
134+
"openapi": "3.0.1",
135+
"info": {
136+
"version": "1.0",
137+
"title": {
138+
"Ref": "AWS::StackName"
139+
}
140+
},
141+
"paths": {
142+
"/hello": {
143+
"get": {
144+
"x-amazon-apigateway-integration": {
145+
"type": "aws_proxy",
146+
"httpMethod": "POST",
147+
"payloadFormatVersion": "2.0",
148+
"uri": {
149+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
150+
}
151+
},
152+
"responses": {},
153+
"security": [
154+
{
155+
"LambdaAuth": []
156+
}
157+
]
158+
},
159+
"put": {
160+
"x-amazon-apigateway-integration": {
161+
"type": "aws_proxy",
162+
"httpMethod": "POST",
163+
"payloadFormatVersion": "2.0",
164+
"uri": {
165+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
166+
}
167+
},
168+
"responses": {},
169+
"security": [
170+
{
171+
"MyOauth2Authorizer": [
172+
"scope"
173+
]
174+
}
175+
]
176+
},
177+
"post": {
178+
"x-amazon-apigateway-integration": {
179+
"type": "aws_proxy",
180+
"httpMethod": "POST",
181+
"payloadFormatVersion": "2.0",
182+
"uri": {
183+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
184+
}
185+
},
186+
"responses": {},
187+
"security": [
188+
{
189+
"LambdaAuth": []
190+
}
191+
]
192+
}
193+
},
194+
"$default": {
195+
"x-amazon-apigateway-any-method": {
196+
"x-amazon-apigateway-integration": {
197+
"type": "aws_proxy",
198+
"httpMethod": "POST",
199+
"payloadFormatVersion": "2.0",
200+
"uri": {
201+
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
202+
}
203+
},
204+
"isDefaultRoute": true,
205+
"responses": {},
206+
"security": [
207+
{
208+
"LambdaAuth": []
209+
}
210+
]
211+
}
212+
}
213+
},
214+
"components": {
215+
"securitySchemes": {
216+
"LambdaAuth": {
217+
"type": "apiKey",
218+
"name": "Unused",
219+
"in": "header",
220+
"x-amazon-apigateway-authorizer": {
221+
"type": "request",
222+
"authorizerUri": {
223+
"Fn::Sub": [
224+
"arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations",
225+
{
226+
"__FunctionArn__": {
227+
"Fn::GetAtt": [
228+
"MyAuthFn",
229+
"Arn"
230+
]
231+
}
232+
}
233+
]
234+
},
235+
"authorizerPayloadFormatVersion": 1.0
236+
}
237+
},
238+
"MyOauth2Authorizer": {
239+
"type": "oauth2",
240+
"x-amazon-apigateway-authorizer": {
241+
"jwtConfiguration": {
242+
"audience": [
243+
"audience1",
244+
"audience2"
245+
],
246+
"issuer": "https://www.example.com/v1/connect/oidc"
247+
},
248+
"identitySource": "$request.header.Authorization",
249+
"type": "jwt"
250+
}
251+
}
252+
}
253+
},
254+
"tags": [
255+
{
256+
"name": "Tag1",
257+
"x-amazon-apigateway-tag-value": "value1"
258+
},
259+
{
260+
"name": "Tag2",
261+
"x-amazon-apigateway-tag-value": "value2"
262+
},
263+
{
264+
"name": "httpapi:createdBy",
265+
"x-amazon-apigateway-tag-value": "SAM"
266+
}
267+
]
268+
}
269+
}
270+
},
271+
"MyApiApiGatewayDefaultStage": {
272+
"Type": "AWS::ApiGatewayV2::Stage",
273+
"Properties": {
274+
"ApiId": {
275+
"Ref": "MyApi"
276+
},
277+
"StageName": "$default",
278+
"Tags": {
279+
"Tag1": "value1",
280+
"Tag2": "value2",
281+
"httpapi:createdBy": "SAM"
282+
},
283+
"AutoDeploy": true
284+
}
285+
}
286+
}
287+
}

0 commit comments

Comments
 (0)