0

我正在尝试为多个部门创建 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 文档作为指南。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.create_activation

https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/SSM/Client.html#create_activation-instance_method

有人可以帮我理解 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.')
4

1 回答 1

1

使用from datetime import datetime而不是import datetime. Datetime 模块本身不可调用,但您可以调用它的属性datetime

于 2020-07-27T21:30:51.023 回答