Help accessing resources in serverless config

I’m trying to figure out how to use LocalStack with serverless. I am figuring out most of it but I am currently having an issue referencing an existing MSK cluster that is not created in the serverless file.

My configuration is basically a lambda, S3 Bucket, and MSK. I am working on a new configuration, but it is based on an existing working project using lambda and MSK. The Serverless file provides the MSK ARN to the Lambda configuration via a CloudFormation parameter ‘cf’. However, when I run serverless with LocalStack I get an error saying the cf isn’t available. Currently I am starting MSK manually in LocalStack , then running Serverless with LocalStack configurations in the serverless file.

Does LocalStack work with serverless and CloudFormation? In particular, using the cf variable? If so, what would I need to do to get it to work, or is there any documentation on how to do this? If not, is there any other way to get a reference to existing services.

Error Message:
mydir $ serverless deploy --stage local
Running “serverless” from node_modules
Environment: linux, node 20.9.0, framework 3.37.0 (local) 3.37.0v (global), plugin 7.2.0, SDK 4.5.1
Credentials: xxx

Error:
Cannot resolve serverless.yml: Variables resolution errored with:

  • Cannot resolve variable at “functions.MyLambda.events.0.msk.arn”: Value not found at “cf” source

Serverless Config snippet:
functions:
MyLambda:
events:
-msk:
arn: ${cf:my–msk-cluster.MSKClusterArn}
topic: my-topic-name
enabled: true
handler: my-lambda-handler
name: my-lambda-name

Hi @tparkerls,
Thanks for reaching out.

Cloudformation, serverless and Localstack plays together pretty well.
However your issue might lie in your CF template as you must expose the value you desire to reference, otherwise serverless won’t be able to pick it up. To do so do something like this.
Given a CF stack with a DynamoDB table, where my stack name is dynamodb-local-stack:

...
Outputs:
 DynamoDbArn:
  Description: DynamoDB ARN
  Value: !GetAtt TodosDynamoDbTable.Arn

To refer to this in Serverless:

Resource: ${cf:dynamodb-local-stack.DynamoDbArn}

Let us know if this helped or you have further questions.