英文:
Transfer of Resources ARN to Lambda
问题
我有一个用Golang编写的Lambda函数。Lambda执行某些操作并调用Step Function。我在代码中硬编码了Step Function的ARN。我不喜欢这个解决方案,想要改进它。目前的工作原理如下:
arn := aws.String(sfnArn) // 例如:arn:aws:states:us-east-1:123:stateMachine:machine-name
params := &sfn.StartExecutionInput{Input: input, Name: name, StateMachineArn: arn}
output, err := client.StartExecution(params)
有什么改进的想法吗?我正在使用Terraform,所以也许有通过TF传递ARN的选项吗?
英文:
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?
答案1
得分: 2
有很多解决这个问题的选项。所以我打算列出一些我想到的,重点是利用AWS服务。
- SSM:将Step Function的ARN保存在SSM参数存储中,并在Lambda运行时使用ssm.GetParameter() API读取该参数。
- Lambda环境变量:您可以将ARN设置为Lambda的环境变量,并使用os.GetEnv()或os.LookupEnv()。
- 资源标签:您可以为Step Function添加一个唯一的标签,然后使用resourcegroupstaggingapi.GetResources() API获取Step Function,然后在代码中从该资源中读取ARN。
显然还有无数其他选项。您可以从S3或EFS读取配置文件,或者将静态配置文件与Lambda捆绑在一起,或者查询基于HTTP的API来读取该值。
英文:
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.
- 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.
- Lambda environment variable: You can set the ARN as environment variable to your Lambda and use os.GetEnv() or os.LookupEnv().
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论