简体   繁体   English

从 EC2 访问 DynamoDB

[英]DynamoDB access From EC2

I have a container running on EC2 which is currently running in a public VPC ( It cannot be changed right now) and, in order for this resource to access DynamoDB, I have created a user, limiting its access to my table in Dynamo and then I created access keys to use in my API calls.我有一个在 EC2 上运行的容器,该容器当前在公共VPC中运行(现在无法更改),为了让此资源访问 DynamoDB,我创建了一个用户,限制其对我在 Dynamo 中的表的访问,然后我创建了访问密钥以用于我的 API 呼叫。

My idea is store these secrets in secret manager and use its SDK from my EC2 to then perform the operations I want to.我的想法是将这些秘密存储在秘密管理器中,然后使用我的 EC2 中的 SDK 来执行我想要的操作。

However, it just seem like a lot of effort and, creating a specific user just to limit the permissions does not seem right for me.但是,这似乎需要付出很多努力,而且创建特定用户只是为了限制权限对我来说似乎并不合适。

Am i in the right way?我走对路了吗? What would be the most interesting approach to access the Dynamo programmatically from my EC2?从我的 EC2 以编程方式访问 Dynamo 的最有趣方法是什么?

I have read somewhere that I could grant role permissions so my EC2 could access my Dynamo.我在某处读到我可以授予角色权限,以便我的 EC2 可以访问我的 Dynamo。 Does that make sense?那有意义吗?

Note: I have an ECS working along my EC2注意:我的 EC2 上有一个 ECS

I am new to AWS and used to work a lot with Azure but mostly with serverless applications where I could easily used the Identity Management feature to grant those permissions.我是 AWS 的新手,过去经常使用 Azure,但主要使用无服务器应用程序,在这些应用程序中我可以轻松使用身份管理功能来授予这些权限。

The details were all mentioned above.详情上面都说了。

I think it would be better to create an instance-profile, define it with the permissions you want for dynamodb, which is pretty much like an iam role and then when you start the instance, use that role.我认为最好创建一个实例配置文件,使用您想要的 dynamodb 权限定义它,这很像一个 iam 角色,然后当您启动实例时,使用该角色。 That means, you do not need to store credentials and this is generally the recommended way to access services from an instance over using access keys.这意味着,您不需要存储凭据,这通常是通过使用访问密钥从实例访问服务的推荐方式。 Ref: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html参考: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html

I have done some search and found this article, it matches exactly your case (EC2 + Dynamo DB)我做了一些搜索并找到了这篇文章,它完全符合您的情况(EC2 + Dynamo DB)

https://awstip.com/using-aws-iam-roles-with-ec2-and-dynamodb-7beb09af31b9 https://awstip.com/using-aws-iam-roles-with-ec2-and-dynamodb-7beb09af31b9

And yes for EC2, the correct approach is to create an IAM role and attach to your instance是的,对于 EC2,正确的方法是创建一个 IAM 角色并附加到您的实例

Also the following command can be used to retrieve the associated credentials (AWS Key + AWS Secret) that are used by that IAM role此外,以下命令可用于检索该 IAM 角色使用的关联凭证(AWS Key + AWS Secret)

curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<name-of-iam-role>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM