微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这段代码是列出所有正在运行的实例,它显示的错误是“errorMessage”:“'s3.ServiceResource' object has no attribute 'object'”

如何解决这段代码是列出所有正在运行的实例,它显示的错误是“errorMessage”:“'s3.ServiceResource' object has no attribute 'object'”

# This code was intended to list all the running instances that I have.

显示 ""errorMessage": "'s3.ServiceResource' object has no attribute 'object'"" 此代码旨在在 AWS Lambda 上运行。我是初学者,因此如果此代码中还有其他错误,请分享您的意见。

import json
import boto3

ec2 = boto3.resource("ec2")
s3 = boto3.resource('s3')
object = s3.Bucket("object")

def lambda_handler(event,context):
    filters = [{"Name" : "instance-state-name","Values" : ["running"]
    }
    ]

    instances = ec2.instances.filter(Filters = filters)

    RunningInstances = []

    for instance in instances:
        RunningInstances.append(instance.id)
        instanceList = json.dumps(RunningInstances)

    s3.object(
            'sameeeeeerjajs','instanceList.txt'
    ).put(Body=instanceList)

    return("Status code:200")

解决方法

从 boto 的 S3.Object 文档来看,它应该是 (Object,而不是 object):

    s3.Object(
            'sameeeeeerjajs','instanceList.txt'
    ).put(Body=instanceList)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。