Is it possible to set up a resource depending on lambda

I would like to create a lambda and associate it with an AWS Config Rule using lambda ARN via Serverless Framework.

I know Serverless Framework can create AWS resources which are supported by CFN in the “resources” section, theoretically including AWS Config rule, but I have not seen any document about how to set up the dependency between “resources” section and lambda.

Any advice?

Use DependsOn attribute in the AWSConfig resource so that it waits for the lambda resource to be created first. Then use intrinsic functions to get the ARN.
{ “Fn::GetAtt” : [ " logicalNameOfResource ", " attributeName " ] }

Thanks for advice.

The challenge here is in serverless.yml, the lambda is not configured with a logic name. It is dynamically generated after running sls cli , so I am not able to fill in lambda logic name in serverless.yml.

I can see the cfn template created by sls cli use ‘ProcessLambdaFunction’ as lambda logic name, but it is not a nice way to hardcode it into severless.yml. Any better approach?

Hmm. Maybe you could use yet another Lambda function. It’s purpose will be to return the ARN of any lambda logical name that is passed into it. Let’s call the function ReturnARNLambdaFunction.

Using boto3 in ReturnARNLambdaFunction, you can use list-functions and grab the ARN of the ProcessLambdaFunction function.

So AWSConfig DependsOn ReturnARNLambdaFunction
ReturnARNLambdaFunction DependsOn ProcessLambdaFunction

The Serverless Framework uses a consistent naming convention so you know the logical name for resources it creates precisely so you can override defaults and reference them.