Skip to content

Commit 0201001

Browse files
villasvbrettstack
authored andcommitted
bug: fix ANY method ARN generation using wildcard (#449)
1 parent 0e89b42 commit 0201001

File tree

10 files changed

+20
-19
lines changed

10 files changed

+20
-19
lines changed

samtranslator/model/eventsources/push.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,12 @@ def _get_permission(self, resources_to_link, stage, suffix):
429429
raise RuntimeError("Could not add permission to lambda function.")
430430

431431
path = self.Path.replace('{proxy+}', '*')
432+
method = '*' if self.Method.lower() == 'any' else self.Method.upper()
432433

433434
api_id = self.RestApiId
434435

435436
# RestApiId can be a simple string or intrinsic function like !Ref. Using Fn::Sub will handle both cases
436-
resource = '${__ApiId__}/' + '${__Stage__}/' + self.Method.upper() + path
437+
resource = '${__ApiId__}/' + '${__Stage__}/' + method + path
437438
partition = ArnGenerator.get_partition_name()
438439
source_arn = fnSub(ArnGenerator.generate_arn(partition=partition, service='execute-api', resource=resource),
439440
{"__ApiId__": api_id, "__Stage__": stage})

tests/translator/output/api_with_cors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"SourceArn": {
8080
"Fn::Sub": [
81-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
81+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
8282
{
8383
"__Stage__": "Prod",
8484
"__ApiId__": {
@@ -428,7 +428,7 @@
428428
},
429429
"SourceArn": {
430430
"Fn::Sub": [
431-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
431+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
432432
{
433433
"__Stage__": "*",
434434
"__ApiId__": {

tests/translator/output/aws-cn/api_with_cors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"SourceArn": {
8080
"Fn::Sub": [
81-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
81+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
8282
{
8383
"__Stage__": "Prod",
8484
"__ApiId__": {
@@ -444,7 +444,7 @@
444444
},
445445
"SourceArn": {
446446
"Fn::Sub": [
447-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
447+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
448448
{
449449
"__Stage__": "*",
450450
"__ApiId__": {

tests/translator/output/aws-cn/implicit_api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -200,7 +200,7 @@
200200
},
201201
"SourceArn": {
202202
"Fn::Sub": [
203-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
203+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
204204
{
205205
"__Stage__": "*",
206206
"__ApiId__": {

tests/translator/output/aws-cn/implicit_api_with_serverless_rest_api_resource.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -200,7 +200,7 @@
200200
},
201201
"SourceArn": {
202202
"Fn::Sub": [
203-
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
203+
"arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
204204
{
205205
"__Stage__": "*",
206206
"__ApiId__": {

tests/translator/output/aws-us-gov/api_with_cors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"SourceArn": {
8080
"Fn::Sub": [
81-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
81+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
8282
{
8383
"__Stage__": "Prod",
8484
"__ApiId__": {
@@ -444,7 +444,7 @@
444444
},
445445
"SourceArn": {
446446
"Fn::Sub": [
447-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/foo",
447+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo",
448448
{
449449
"__Stage__": "*",
450450
"__ApiId__": {

tests/translator/output/aws-us-gov/implicit_api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -210,7 +210,7 @@
210210
},
211211
"SourceArn": {
212212
"Fn::Sub": [
213-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
213+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
214214
{
215215
"__Stage__": "*",
216216
"__ApiId__": {

tests/translator/output/aws-us-gov/implicit_api_with_serverless_rest_api_resource.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -210,7 +210,7 @@
210210
},
211211
"SourceArn": {
212212
"Fn::Sub": [
213-
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
213+
"arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
214214
{
215215
"__Stage__": "*",
216216
"__ApiId__": {

tests/translator/output/implicit_api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -200,7 +200,7 @@
200200
},
201201
"SourceArn": {
202202
"Fn::Sub": [
203-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
203+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
204204
{
205205
"__Stage__": "*",
206206
"__ApiId__": {

tests/translator/output/implicit_api_with_serverless_rest_api_resource.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SourceArn": {
100100
"Fn::Sub": [
101-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
101+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
102102
{
103103
"__Stage__": "Prod",
104104
"__ApiId__": {
@@ -200,7 +200,7 @@
200200
},
201201
"SourceArn": {
202202
"Fn::Sub": [
203-
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/ANY/*",
203+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
204204
{
205205
"__Stage__": "*",
206206
"__ApiId__": {

0 commit comments

Comments
 (0)