Skip to content

Commit 990c7f6

Browse files
keetonianjlhood
authored andcommitted
fix: allow setting InvokeRole to NONE or null (#986)
1 parent 0712837 commit 990c7f6

File tree

7 files changed

+2172
-670
lines changed

7 files changed

+2172
-670
lines changed

examples/2016-10-31/api_aws_iam_auth/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Resources:
88
StageName: Prod
99
Auth:
1010
DefaultAuthorizer: AWS_IAM
11-
InvokeRole: CALLER_CREDENTIALS
11+
InvokeRole: CALLER_CREDENTIALS # default, can specify other role or NONE
1212

1313
MyFunction:
1414
Type: AWS::Serverless::Function

samtranslator/swagger/swagger.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,18 @@ def add_lambda_integration(self, path, method, integration_uri,
169169
api_auth_config = api_auth_config or {}
170170
if method_auth_config.get('Authorizer') == 'AWS_IAM' \
171171
or api_auth_config.get('DefaultAuthorizer') == 'AWS_IAM' and not method_auth_config:
172-
self.paths[path][method][self._X_APIGW_INTEGRATION]['credentials'] = self._generate_integration_credentials(
173-
method_invoke_role=method_auth_config.get('InvokeRole'),
174-
api_invoke_role=api_auth_config.get('InvokeRole')
172+
method_invoke_role = method_auth_config.get('InvokeRole')
173+
if not method_invoke_role and 'InvokeRole' in method_auth_config:
174+
method_invoke_role = 'NONE'
175+
api_invoke_role = api_auth_config.get('InvokeRole')
176+
if not api_invoke_role and 'InvokeRole' in api_auth_config:
177+
api_invoke_role = 'NONE'
178+
credentials = self._generate_integration_credentials(
179+
method_invoke_role=method_invoke_role,
180+
api_invoke_role=api_invoke_role
175181
)
182+
if credentials and credentials != 'NONE':
183+
self.paths[path][method][self._X_APIGW_INTEGRATION]['credentials'] = credentials
176184

177185
# If 'responses' key is *not* present, add it with an empty dict as value
178186
path_dict[method].setdefault('responses', {})

tests/translator/input/api_with_aws_iam_auth_overrides.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
Resources:
2+
MyApiWithAwsIamAuthNoCallerCredentials:
3+
Type: "AWS::Serverless::Api"
4+
Properties:
5+
StageName: Prod
6+
Auth:
7+
DefaultAuthorizer: AWS_IAM
8+
InvokeRole: NONE
29
MyApiWithAwsIamAuth:
310
Type: "AWS::Serverless::Api"
411
Properties:
@@ -84,3 +91,64 @@ Resources:
8491
Auth:
8592
Authorizer: AWS_IAM
8693
InvokeRole: arn:aws:iam::456::role/something-else
94+
MyFunctionNONEInvokeRole:
95+
Type: AWS::Serverless::Function
96+
Properties:
97+
CodeUri: s3://bucket/key
98+
Handler: index.handler
99+
Runtime: nodejs8.10
100+
Events:
101+
API3:
102+
Type: Api
103+
Properties:
104+
RestApiId: !Ref MyApiWithAwsIamAuth
105+
Method: get
106+
Path: /MyFunctionNONEInvokeRole
107+
Auth:
108+
Authorizer: AWS_IAM
109+
InvokeRole: NONE
110+
MyFunctionNullInvokeRole:
111+
Type: AWS::Serverless::Function
112+
Properties:
113+
CodeUri: s3://bucket/key
114+
Handler: index.handler
115+
Runtime: nodejs8.10
116+
Events:
117+
API3:
118+
Type: Api
119+
Properties:
120+
RestApiId: !Ref MyApiWithAwsIamAuth
121+
Method: get
122+
Path: /MyFunctionNullInvokeRole
123+
Auth:
124+
Authorizer: AWS_IAM
125+
InvokeRole: null
126+
MyFunctionCallerCredentialsOverride:
127+
Type: AWS::Serverless::Function
128+
Properties:
129+
CodeUri: s3://bucket/key
130+
Handler: index.handler
131+
Runtime: nodejs8.10
132+
Events:
133+
API3:
134+
Type: Api
135+
Properties:
136+
RestApiId: !Ref MyApiWithAwsIamAuthNoCallerCredentials
137+
Method: get
138+
Path: /
139+
Auth:
140+
Authorizer: AWS_IAM
141+
InvokeRole: CALLER_CREDENTIALS
142+
MyFunctionNoCallerCredentials:
143+
Type: AWS::Serverless::Function
144+
Properties:
145+
CodeUri: s3://bucket/key
146+
Handler: index.handler
147+
Runtime: nodejs8.10
148+
Events:
149+
API3:
150+
Type: Api
151+
Properties:
152+
RestApiId: !Ref MyApiWithAwsIamAuthNoCallerCredentials
153+
Method: post
154+
Path: /

0 commit comments

Comments
 (0)