Output FunctionUrl from AWS::Serverless::Function with URL

2

I defined a AWS::Serverless::Function like follows:

  GreetingsFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs16.x
      Architectures:
        - x86_64
      InlineCode: !Sub |
        exports.handler = async () => {
          return {
              'statusCode': 200,
              'body': JSON.stringify({message: "Greetings from ${AWS::Region}"})
              };
          };
      FunctionUrlConfig:
        AuthType: NONE
        Cors:
          AllowOrigins:
            - "*"

I want to include FunctionUrl in the Outputs of my template. I tried !GetAtt GreetingsFunction.FunctionUrl hoping that the corresponding AWS::Lambda::Url attribute would propagate to AWS::Serverless::Function but this was not the case.

How do I retrieve the function URL?

Romanko
已提問 2 年前檢視次數 1260 次
1 個回答
1
已接受的答案

To get this output, you need to know that SAM automatically creates a AWS::Lambda::Ur resource for you under the hood, which is just the function's resource ID with "...Url" appended to it.

You can get the value you want with this Outputs snippet:

Outputs:
  GreetingsFunction:
    Description: "Function URL for GreetingsFunction"
    Value:
      Fn::GetAtt: GreetingsFunctionUrl.FunctionUrl
profile picture
rowanu
已回答 2 年前
  • Thank you, rowanu, that worked. I saw the AWS::Lambda::Url resource created by SAM but was not sure if it was accessible from the untransformed template.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南