如何在AWS中设置DynamoDB环境变量?

huangapple go评论51阅读模式
英文:

How to set a DynamoDB environment variable in AWS?

问题

我有一个连接到 DynamoDB 的 Golang 代码。

数据库表的名称是硬编码的,现在已经设置为使用 os.LookupEnv() 从环境变量中读取。

我在本地进行了单元测试,变量是从 secrets.env 文件中读取的,但我想知道如何在部署到生产环境时使其正常工作?

我想我需要在 AWS 配置中进行设置?

英文:

I have a Golang which connects to a DynamoDB.

The name of the db table was hard-coded and now it is set to read from an environment variable using os.LookupEnv().

I unit tested locally with the variable being read from a secrets.env file, but I wonder how to proceed to make it work when deployed in production?

I suppose that I need to set this on AWS config somehow?

答案1

得分: 3

不会将它存储在aws config中,该配置用于配置访问密钥,我也建议不要这样做,最佳做法是使用附加到您正在使用的服务的IAM角色。

至于DynamoDB表名作为环境变量,完全取决于您希望如何处理。您可以将其存储为EC2操作系统上的环境变量,例如。或者,如果使用Lambda,您可以使用其环境变量

您还可以使用Parameter Store来存储环境变量,这是一种常见的做法。

英文:

No, you would not store it in aws config that is for configuring access keys, which I also recommend not doing, use an IAM role attached to whichever service you are using is best practice.

As for DynamoDB table name as an env variable, its totally up to how you wish to do it. You can store it as an env variable on the OS in EC2 for example. Or if using Lambda you can use its Environment Variables

You can also use Parameter Store to store environments variables and is common practice.

huangapple
  • 本文由 发表于 2023年2月8日 20:59:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定