python-3.x - AWS SSM Python / Boto3 创建混合激活 ExpirationDate 类型错误
问题描述
我正在尝试为多个部门创建 AWS SSM 混合激活。我的 IDE 告诉我 datetime 不可调用,我收到的错误消息是:
Traceback (most recent call last):
File "C:\Users\username\bin\Create-Activation.py", line 23, in <module>
ExpirationDate = datetime(y, m, d),
TypeError: 'module' object is not callable
变量 y、m 和 d 被传递给 ExpirationDate 对象。我使用 Amazon 和 Boto3 文档作为指南。
有人可以帮我理解 ExpirationDate 对象失败的原因吗?
import boto3
import datetime
client = boto3.client('ssm')
current_date = datetime.date.today()
creation_date = current_date.strftime('%Y%m%d')
end_date = current_date + datetime.timedelta(days=30)
y = end_date.year
m = end_date.month
d = end_date.day
divisions = ['div1', 'div2', 'div3']
#def lambda_handler(event, context):
for x in divisions:
client.create_activation(
Description = (x + '-' + 'creation_date'),
#DefaultInstanceName = 'string',
IamRole = 'MySSMServiceRole',
RegistrationLimit = 200,
ExpirationDate = datetime(y, m, d),
Tags=[
{
'Key': 'Division',
'Value': x
},
]
)
print('\n ' + x + '-creation_date was create.')
解决方案
使用from datetime import datetime
而不是import datetime
. Datetime 模块本身不可调用,但您可以调用它的属性datetime
。
推荐阅读
- android - 如何随机更改字符串数组的值?
- java - 使用改造向服务器发送发布请求
- node.js - 无法从 forloop 获得预期的输出
- c# - C# GetAsync 不适用于 Django Rest 框架
- sql - 在不同的表上插入/更新条件
- minikube - 如何在 minikube 上安装/使用 tcpdump?
- ios - 颤振-ios EXC_BAD_ACCESS [main.m : 7]
- google-apps-script - Check if cell is empty
- sql - 如何将日期时间的转换存储在具有新列名的新列中,可以在其上使用 ORDER BY?
- automated-tests - 如何单击应该在“touchmove”事件中消失的元素?