简体   繁体   English

向 ECS/Fargate 中的 AWS CLI 提供凭证

[英]Providing credentials to the AWS CLI in ECS/Fargate

I would like to create an ECS task with Fargate, and have that upload a file to S3 using the AWS CLI (among other things).我想使用 Fargate 创建一个 ECS 任务,并使用 AWS CLI(除其他外)将文件上传到 S3。 I know that it's possible to create task roles, which can provide the task with permissions on AWS services/resources.我知道可以创建任务角色,它可以为任务提供对 AWS 服务/资源的权限。 Similarly, in OpsWorks, the AWS SDK is able to query instance metadata to obtain temporary credentials for its instance profile.同样,在 OpsWorks 中,AWS SDK 能够查询实例元数据以获取其实例配置文件的临时凭证。 I also found these docs suggesting that something similar is possible with the AWS CLI on EC2 instances.我还发现这些文档表明在 EC2 实例上使用 AWS CLI 也可以实现类似的功能。

Is there an equivalent for Fargate—ie, can the AWS CLI, running in a Fargate container, query the metadata service for temporary credentials? Fargate 是否有等效项——即,在 Fargate 容器中运行的 AWS CLI 是否可以查询元数据服务以获取临时凭证? If not, what's a good way to authenticate so that I can upload a file to S3?如果没有,什么是进行身份验证以便我可以将文件上传到 S3 的好方法? Should I just create a user for this task and pass in AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables?我是否应该为此任务创建一个用户并将AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY作为环境变量传递?

(I know it's possible to have an ECS task backed by EC2, but this task is short-lived and run maybe monthly; it seemed a good fit for Fargate.) (我知道可以有一个由 EC2 支持的 ECS 任务,但这个任务是短暂的,可能每月运行一次;它似乎很适合 Fargate。)

"I know that it's possible to create task roles, which can provide the task with permissions on AWS services/resources." “我知道可以创建任务角色,它可以为任务提供对 AWS 服务/资源的权限。”

"Is there an equivalent for Fargate" “是否有 Fargate 的等效项”

You already know the answer.你已经知道答案了。 The ECS task role isn't specific to EC2 deployments, it works with Fargate deployments as well. ECS 任务角色并非特定于 EC2 部署,它也适用于 Fargate 部署。

You can get the task metadata, including IAM access keys, through the ECS metadata service .您可以通过ECS 元数据服务获取任务元数据,包括 IAM 访问密钥。 But you don't need to worry about that, because the AWS CLI, and any AWS SDK, will automatically pull that information when it is running inside an ECS task.但您无需为此担心,因为 AWS CLI 和任何 AWS SDK 会在 ECS 任务中运行时自动提取该信息。

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

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