0

I have created a pure python lambda function in python chalice app.py like so:

@app.lambda_function('R53CloudformationResourceConflict')
def r53_cloudformation_resource_conflict(event, context):
    logger.info(event)
    logger.info(context)

Now the next part I am trying to do is call this lambda as a custom resource from a separate cloud formation template(cf.yml) as so:

AWSTemplateFormatVersion: 2010-09-09

Parameters:
  LambdaFunctionName:
    Type: String

Resources:
  R53CloudformationResourceConflict:
    Type: 'Custom::R53CloudformationResourceConflict'
    Properties:
      ServiceToken: !Join [ '', ['arn:aws:lambda:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':function:', !Ref LambdaFunctionName] ]
      AppUrl: "some_app_url"

My file structure:

├── cf.yml
└── custom-lambda
    ├── app.py
    └── requirements.txt

Currently python chalice prepends {{ app-name }}- {{ chalice-stage }} to the pure lambda function name. So for this instance the final lambda name is custom-lambda-dev-R53CloudformationResourceConflict.

Now the bit I am stuck on is dynamically knowing what my lambda function will be called(different stages, possibly app name change) and referencing that in the separate Cloud Formation stack(cf.yml) dynamically.

I have found https://chalice.readthedocs.io/en/stable/topics/configfile.html#lambda-specific-configuration this which might help but again this is fixed not dynamic.

Is there a relatively simply way to reference this pure lambda function created by python chalice in a separate Cloud Formation template in the same repo?

Justin S
  • 1,409
  • 4
  • 22
  • 38

1 Answers1

0

In a chalice application, you will have multiple stages: prod/dev/test.

Lambda names are really predictable and they do not change.

{appname}-{env}-{lambdaname}

Lets assume the chalice app is helloworld and your lambda name = greetings:

If you want to reference your prod lambda: helloworld-prod-greetings If you want to reference your test lambda: helloworld-test-greetings If you want to reference your dev lambda: helloworld-dev-greetings

You select which stage you deploy during the deployment of chalice:

chalice deploy --stage prod

You can find the stages defined in your application in the file .chalice/config.json Look for the key stages.

Also you should store and check your "state files" .chalice/deployed/{stage}.json

albert
  • 4,290
  • 1
  • 21
  • 42