Search code examples
python-3.xamazon-web-servicesboto3amazon-systems-manager

AWS SSM Python / Boto3 Create Hybrid Activation ExpirationDate Type Error


I am trying to create AWS SSM Hybrid activations for multiple divisions. My IDE is telling me that datetime is not callable, and the error message I am getting is:

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

The variables y, m, and d are being passed to ExpirationDate object. I am using the Amazon and Boto3 documentation as a guide.

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

Can someone help me understand why the ExpirationDate object is failing?

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.')

Solution

  • Use from datetime import datetime instead of import datetime. Datetime modules itself not callable, but you can call its attribute datetime.