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
feita há 2 anos1259 visualizações
1 Resposta
1
Resposta aceita

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 há 2 anos
  • 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.

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas