传递S3cmd命令,用户数据EC2命令、数据、用户、S3cmd

2023-09-11 09:31:49 作者:快乐的仙人掌

我有一个AWS EC2实例。从这个EC2实例我创建从EC2实例。

i am having one AWS EC2 instance. From this EC2 instance i am creating slave EC2 instances.

和同时建立从实例我传递用户数据到新的从instance.In我已经写了code在EC2实例创建新的目录,并从S3存储下载文件的用户数据。

And while creating slave instances i am passing user data to new slave instance.In that user data i have written code for creating new directory in EC2 instance and downloading file from S3 bucket.

但问题是,剧本在EC2实例创建新的目录,但它无法从S3存储下载文件。

but problem is that, script creates new directory on EC2 instance but it Fails to download file from S3 bucket.

用户数据脚本: -

User Data Script :-

#! /bin/bash
cd /home 
mkdir pravin 
s3cmd get s3://bucket/usr.sh >> download.log

如上图所示,在此code 的mkdir普拉创建目录,但 s3cmd获取S3://bucket/usr.sh 无法下载文件和 download.log 文件也得到创建,但它仍然是空的。

As shown above,in this code mkdir pravin create directory but s3cmd get s3://bucket/usr.sh fails to download file and download.log file also gets created but it remains empty.

我该如何解决这个proble,? (AMI用于这是pconfigured与s3cmd $ P $)

How can i solve this proble, ? (AMI used for this is preconfigured with s3cmd)

推荐答案

您运行Ubuntu的机会呢?然后什洛莫斯威德勒的问题的Python s3cmd只能从登录shell运行,而不是在启动顺序可能正好适用:

Are you by chance running Ubuntu? Then Shlomo Swidler's question Python s3cmd only runs from login shell, not during startup sequence might apply exactly:

在s3cmd Python脚本(这一个: http://s3tools.org/s3cmd )似乎只工作通过交互式登录会话中运行时,而不是通过脚本在引导过程中运行时。

The s3cmd Python script (this one: http://s3tools.org/s3cmd ) seems to only work when run via an interactive login session, but not when run via scripts during the boot process.

米奇Garnaat表明是每个人都应该提防环境通过用户数据的脚本中执行code造成的差异的:

Mitch Garnaat suggests that one should always beware of environmental differences inflicted by executing code within User-Data Scripts:

它可能关系到你的环境中,当你,而不是当脚本运行作为启动序列的一部分来登录一些差异。我遇到了类似的问题cron作业。

It's probably related to some difference in your environment when you are logged in as opposed to when the script is running as part of the startup sequence. I have run into similar problems with cron jobs.

这竟然是这个问题确实什洛莫斯威德勒总结的根本原因,并在这个线程的解决方案进一步下跌:

This turned out to be the problem indeed, Shlomo Swidler summarizes the 'root cause' and a solution further down in this thread:

米奇,您的评论让我认识到什么是不同有关   启动顺序:手术是root用户。当我登录,我的   Ubuntu的用户。

系统硬件综合设计 多周期CPU的设计与实现

Mitch, your comment helped me realize what's different about the startup sequence: the operative user is root. When I log in, I'm the "ubuntu" user.

s3cmd查找当前用户的〜/ .s3cfg - 这并不在存在   /root/.s3cfg,仅在/home/ubuntu/.s3cfg

s3cmd looks in the current user's ~/.s3cfg - which didn't exist in /root/.s3cfg, only in /home/ubuntu/.s3cfg.

幸运的是s3cmd允许您使用指定配置文件的位置   --config /home/ubuntu/.s3cfg。

Luckily s3cmd allow you to specify the config file's location with --config /home/ubuntu/.s3cfg .

 
精彩推荐
图片推荐