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
demandé il y a 2 ans1259 vues
1 réponse
1
Réponse acceptée

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
répondu il y a 2 ans
  • 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.

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions