python - 在 ec2 和 boto3 中使用过滤器的混乱
问题描述
我正在尝试打印我的实例的公共 DNS 名称
所以我在这里写了一个代码
import sys
import boto3
instance_id = "i-03e7f6391a0f523ee"
action = 'ON'
ec2 = boto3.client('ec2')
if action == 'ON':
response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False)
else:
response = ec2.stop_instances(InstanceIds=[instance_id], DryRun=False)
print(response)
resp=ec2.describe_network_interfaces();
print ("printing pub dns name")
print(resp['NetworkInterfaces'][0]['Association']['PublicDnsName'])
def get_name(inst):
client = boto3.client('ec2')
response = client.describe_instances(InstanceIds = [inst[0].instance_id])
foo = response['Reservations'][0]['Instances'][0]['NetworkInterfaces'][0]['Association']['PublicDnsName']
return foo
foo = get_name(instance_id)
print (foo)
我得到的错误是在行
response = client.describe_instances(InstanceIds = [inst[0].instance_id])
在 get_name 中
response = client.describe_instances(InstanceIds = [inst[0].instance_id])
AttributeError: 'str' object has no attribute 'instance_id'
我如何在这里使用过滤器?
解决方案
推荐阅读
- javascript - vue-google-chart 如何在选择过滤器点击时更改颜色?
- ajax - Yii2中如何让ajax更新和ajax验证一起工作?
- react-native - 如何为反应本机堆栈导航器指定默认屏幕?
- python - 将请求设置并推送到一个请求中 Django MongoEngine MongoDB
- javascript - 如何通过 url 触发弹出窗口
- html - 如何使用 Bootstrap v5.1 在剩余可用空间的中心对齐 DIV 元素
- postman - Postman / Newman 并从 Azure Blob 上传文件而不是本地文件
- docker - docker 引擎创建的 iptables 规则
- rust - 如何使用父成员的方法获取工作区成员的版本?
- python - 整个数据帧的最大索引?