我试图弄清楚如何使用boto3进行正确的错误处理。

我正在尝试创建一个IAM用户:

def create_user(username, iam_conn):
    try:
        user = iam_conn.create_user(UserName=username)
        return user
    except Exception as e:
        return e

当调用create_user成功时,我得到一个整洁的对象,其中包含API调用的http状态代码和新创建用户的数据。

例子:

{'ResponseMetadata': 
      {'HTTPStatusCode': 200, 
       'RequestId': 'omitted'
      },
 u'User': {u'Arn': 'arn:aws:iam::omitted:user/omitted',
           u'CreateDate': datetime.datetime(2015, 10, 11, 17, 13, 5, 882000, tzinfo=tzutc()),
           u'Path': '/',
           u'UserId': 'omitted',
           u'UserName': 'omitted'
          }
}

这很有效。但是当这个失败时(比如如果用户已经存在),我只得到一个botocore.exceptions.ClientError类型的对象,其中只有文本告诉我哪里出错了。

例子: ClientError('调用CreateUser操作时发生错误(EntityAlreadyExists):省略名称的用户已经存在。')

这(AFAIK)使得错误处理非常困难,因为我不能只是打开结果的http状态代码(409用户已经存在根据AWS API文档的IAM)。这让我觉得我一定是做错了什么。最优的方法是boto3永远不抛出异常,但juts总是返回一个反映API调用如何进行的对象。

有没有人能在这个问题上给我一些启发,或者给我指出正确的方向?

我正在尝试停止Amazon EC2实例并获得警告消息

警告:请注意,实例的临时存储上的任何数据在停止时都将丢失。

我的问题

哪些数据存储在Amazon EC2实例的临时存储中?

我有一个boto3客户端:

boto3.client('kms')

但这发生在新机器上,它们动态地打开和关闭。

    if endpoint is None:
        if region_name is None:
            # Raise a more specific error message that will give
            # better guidance to the user what needs to happen.
            raise NoRegionError()

为什么会这样?为什么只是部分时间?

如何通过ssh连接到AWS实例?

我有:

Signed up at AWS; Created a public key and a certificate at AWS website and saved them to disk; Went to my console and created environment variables: $ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/ $ export EC2_CERT=/home/default/aws/cert-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem $ export EC2_PRIVATE_KEY=/home/default/aws/pk-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem Told AWS API to use this keypair and saved the keypair to file: $ ec2-add-keypair ec2-keypair > ec2-keypair.pem Started an AWS Ubuntu 9 instance using this keypair: $ ec2-run-instances ami-ed46a784 -k ec2-keypair Attempted to establish a ssh connection to the instance: $ ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to ec2-174-129-185-190.compute-1.amazonaws.com [174.129.185.190] port 22. debug1: Connection established. debug1: identity file ec2-keypair.pem type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5ubuntu1 debug1: match: OpenSSH_5.1p1 Debian-5ubuntu1 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-cbc hmac-md5 none debug1: kex: client->server aes128-cbc hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host 'ec2-174-129-185-190.compute-1.amazonaws.com' is known and matches the RSA host key. debug1: Found key in /home/default/.ssh/known_hosts:11 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: ec2-keypair.pem debug1: read PEM private key done: type RSA debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey). What could be the problem and how to make it work?

Amazon S3中是否有重命名文件和文件夹的功能?欢迎提出相关建议。

我使用S3托管一个javascript应用程序,将使用HTML5 pushStates。问题是,如果用户书签了任何url,它将不会解析为任何东西。我需要的是能够接受所有url请求,并在我的S3桶中提供根index.html,而不仅仅是进行完全重定向。然后我的javascript应用程序可以解析URL并提供适当的页面。

有没有办法告诉S3为所有URL请求服务index.html,而不是做重定向?这类似于通过提供一个index.html来设置apache来处理所有传入的请求,如本例中的https://stackoverflow.com/a/10647521/1762614。我真的希望避免仅仅为了处理这些路由而运行web服务器。从S3执行所有操作非常有吸引力。

我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。

如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?

如何在Amazon S3中设置一个桶,使所有文件默认为公开只读?

我目前正在运行一个ec2微实例,我发现实例偶尔会内存不足。

除了使用更大的实例大小,还可以做什么?

我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。

我如何能使实例pingable?