aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Sam cli - Unable to parse Function Name from function arn #714

Closed revolutionisme closed 3 years ago

revolutionisme commented 6 years ago

Description: I have an api defined in swagger like the following in my appspec.yml file:

        /test:
            post:
              responses: {}
              security:
                - sigv4: []
              x-amazon-apigateway-request-validator: "Validate query string parameters and headers"
              x-amazon-apigateway-integration:
                uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction}/invocations"
                passthroughBehavior: "when_no_match"
                httpMethod: "POST"
                authorizationType: "NONE"
                cacheNamespace: "namespace-2"
                type: "aws_proxy"

Whenever I start start sam cli, i see messages like follows:

2018-10-18 10:01:34 Detected Inline Swagger definition
2018-10-18 10:01:34 Resolved Sub intrinsic function: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction}/invocations
2018-10-18 10:01:34 Extracted Function ARN: arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction}
2018-10-18 10:01:34 Ignoring integration ARN. Unable to parse Function Name from function arn arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction}
2018-10-18 10:01:34 Lambda function integration not found in Swagger document at path='/test' method='post'

Now to fix the issue, I tried the following after seeing some example some where. I basically changed added ".Arn" after function name in my uri of the swagger definition.

uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction.Arn}/invocations"

The thing is, that this resolved the issue with sam cli (even sam validate validated the template). And I got the following logs:

Resolved Sub intrinsic function: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:arn:aws:lambda:${AWS::Region}:123456789012:function:LambdaFunction/invocations
2018-10-18 10:14:44 Extracted Function ARN: arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:arn:aws:lambda:${AWS::Region}:123456789012:function:LambdaFunction

But when I used the same template to upload to cloudformation and run, it threw me the following error.

{"message": "1 validation error detected: Value \'arn:aws:lambda:eu-central-1:023966115288:function:arn:aws:lambda:eu-central-1:023966115288:function:test-repo-LamdaFunct-8BUEQ58CM1GA\' at \'functionName\' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-\.]+)(:(\$LATEST|[a-zA-Z0-9-]+))?"}

which is obvious as it resolved the function arn completely on top of the manually generated arn.

So the issue is why didn't it throw the same error with sam cli?

Steps to reproduce the issue:

  1. Use uri like as follows in the swagger api definition: uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction.Arn}/invocations"
  2. Test it with sam cli
  3. Run the same specification with cloudformation

Observed result: Runs succesfully in Sam cli, Fails with cloud formation

Expected result: Fail in both the situation or pass in both the situation

Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Mac

Output of sam --version: SAM CLI, version 0.6.0

sparrowt commented 6 years ago

In the error message from cloudformation which you posted above, this part is incorrectly duplicated arn:aws:lambda:eu-central-1:023966115288:function.

I think instead of

uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction.Arn}/invocations"

you need

uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations"

because ${LambdaFunction.Arn} should expand to arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:FUNCTIONNAME.

CoshUS commented 3 years ago

Closing as the comment above. Let me know if there are other issues.

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.