【发布时间】:2020-07-27 21:03:11
【问题描述】:
我正在尝试为多个部门创建 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 datetimeTraceback (most recent call last): File "C:\Users\jmoorhead\bin\Create-Activation.py", line 7, in <module> current_date = datetime.date.today() AttributeError: 'method_descriptor' object has no attribute 'today'后得到的结果 -
使用
current_date = datetime.today()。正如我提到的,使用 dir() 来检查对象的属性。 -
谢谢萨兰吉特。我最终使用了
from datetime import datetime, timedelta并修改了我的几个变量。print(dir(datetime))在这样做时非常有用。 -
乐于帮助@jmoorhead :)
标签: python-3.x amazon-web-services boto3 amazon-systems-manager