简体   繁体   English

如何使用 cloudformation 模板中的用户数据将文件从 s3 存储桶复制到 ec2 实例中

[英]How can I copy a file from s3 bucket into an ec2 instance using userdata inside a cloudformation template

I need to be able to copy some files from s3 bucket into ec2 instance during launch time .我需要能够在启动期间将一些文件从 s3 存储桶复制到 ec2 实例中。 Is it possible to do so via user data section of the cloudformation template?是否可以通过 cloudformation 模板的用户数据部分来实现?

Fyi, I have the role attached to the instance to access s3 and I am able to copy files using aws cli but I need to be able to do so via user data inside cloudformation without using aws cli, if possible at all.仅供参考,我将角色附加到实例以访问 s3,我能够使用 aws cli 复制文件,但我需要能够通过 cloudformation 中的用户数据进行复制,而无需使用 aws cli,如果可能的话。

Edit--编辑 -

Object in s3 is publicly accessible at the moment and the instance is using a custom red hat ami. s3 中的对象目前是可公开访问的,并且该实例使用的是自定义的 red hat ami。

If the object in Amazon S3 is publicly accessible, you could download it with curl :如果 Amazon S3 中的对象可公开访问,您可以使用curl下载它:

curl -o output.file https://my-bucket.s3-us-west-2.amazonaws.com/file.txt

If wget is installed, you could use that instead.如果安装了wget ,您可以改用它。

If the object is private, it will require authentication using the role.如果对象是私有的,则需要使用角色进行身份验证。 This will require some form of software to be installed, so it would be simpler to just install the AWS CLI.这将需要安装某种形式的软件,因此安装 AWS CLI 会更简单。

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

相关问题 我无法使用CloudFormation中的Userdata将S3文件复制到EC2实例 - I am not able to copy S3 file to EC2 instance using Userdata in CloudFormation 如何使用 lambda function 将文件从 s3 存储桶复制到 ec2 实例? - How do I copy a file from s3 bucket to ec2 instance using lambda function? 如何使用 AWS Lambda 函数将文件从 S3 存储桶复制到 EC2 Windows 实例 - How to copy a file from S3 bucket to an EC2 Windows instance using AWS Lambda function 如何在 CloudFormation 模板中将数据从 AWS S3 复制到 EC2? - How do I copy data from AWS S3 to EC2 in a CloudFormation template? 如何从EC2实例导航到S3存储桶文件夹? - How can I navigate into S3 bucket folders from EC2 instance? 使用 python 将文件从 s3 存储桶复制到 ec2 实例 - Copy files from s3 bucket to ec2 instance using python 使用 Lambda 将文件从 S3 存储桶复制到 EC2 Windows 实例 - Copy files from S3 bucket to EC2 Windows Instance using Lambda 如何将整个文件夹从s3存储桶复制到ec2实例 - How to copy an entire folder from s3 bucket to ec2 instance 如何从EC2实例访问S3存储桶 - How to access s3 bucket from ec2 instance 如何使用CloudFormation模板从S3获取用于引导应用程序的文件,而无需启动具有角色的EC2实例? - How to get file from S3 for bootstrapping application using CloudFormation template and without launching EC2 instances with a role?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM