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
preguntada hace 2 años1259 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
respondido hace 2 años
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas