1

I have set up CI/CD for an AWS Lambda function such that the new version is automatically deployed using GitHub actions. By default, AWS creates a new Lambda ID (and thus URL) for this lambda function. This means that the front-end portion of my code will need to be updated to contain the updated URL. Is there a way to automatically perform such updating? By e.g. saving the URL as an environment variable and inserting it in the code with a GitHub action?

Or is there alternatively a way to re-use the old Lambda function URL for new deployments?

Bas Krahmer
  • 489
  • 5
  • 11
  • "By default, AWS creates a new Lambda ID (and thus URL) for this lambda function." That isn't correct. Can you share the exact operations you use in your github action? – erik258 Oct 05 '22 at 23:03
  • The commands are `sam build --use-container --template-file template.yaml` and `sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name stack_name`; but perhaps this is something specific to SAM actually? – Bas Krahmer Oct 06 '22 at 09:02

1 Answers1

0

You can get the updated Lambda URL by using SAM template outputs as follows:

Resources:
  MyFunction:
    Type: 'AWS::Serverless::Function'

Outputs:
  MyFunctionUrlEndpoint:
    Description: "My Lambda Function URL Endpoint"
    Value: !GetAtt MyFunctionUrl.FunctionUrl

Then you can access the output as described in this answer:

aws cloudformation describe-stacks --stack-name stack_name --query 'Stacks[0].Outputs[?OutputKey==`MyFunctionUrlEndpoint`].OutputValue' --output text

which can then be further processed in e.g. your front-end code.

There may be easier methods, but this should work!

Bas Krahmer
  • 489
  • 5
  • 11