eL_
eL_

Reputation: 177

Transfer of Resources ARN to Lambda

I have Lambda written in Golang. Lambda does some action and invoke Step Function. I have hard coded Step Function ARN in the code. I don't like this solution and would like to improve it. How it works right now:

arn := aws.String(sfnArn) // e.g: arn:aws:states:us-east-1:123:stateMachine:machine-name
params := &sfn.StartExecutionInput{Input: input, Name: name, StateMachineArn: arn}

output, err := client.StartExecution(params)

Any idea how to improve it? I'm using Terraform so maybe there is any option to pass ARN through TF?

Upvotes: 1

Views: 412

Answers (1)

Jens
Jens

Reputation: 21530

There are a lot of options how to solve this issue. So I am going to name the once that come to my mind with focus of leveraging AWS services.

  1. SSM: save the ARN of the Step Function in the SSM parameter store and read this parameter when your Lambda runs using the ssm.GetParameter() API.
  2. Lambda environment variable: You can set the ARN as environment variable to your Lambda and use os.GetEnv() or os.LookupEnv().
  3. Resource Tags: You can give your Step Function a tag that is unique to it and then use the resourcegroupstaggingapi.GetResources() API to get the Step Function and then read the ARN from that resource in your code.

There are obviously a million more options. You could read a configuration file from S3 or EFS or bundle a static configuration file with your Lambda or query HTTP based API to read that value.

Upvotes: 2

Related Questions