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
asked 2 years ago1235 views
1 Answer
1
Accepted Answer

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
answered 2 years ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions