0

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.')
jmoorhead
  • 393
  • 1
  • 4
  • 19
  • Thank you for the update. This is what I'm getting after using `from datetime import datetime` `Traceback (most recent call last): File "C:\Users\jmoorhead\bin\Create-Activation.py", line 7, in current_date = datetime.date.today() AttributeError: 'method_descriptor' object has no attribute 'today'` – jmoorhead Jul 27 '20 at 22:05
  • use `current_date = datetime.today()` . As I mentioned, use dir() to check the attributes of objects. – saranjeet singh Jul 28 '20 at 09:12
  • Thank you Saranjeet. I ended up using `from datetime import datetime, timedelta` and modifying a couple of my variables. The `print(dir(datetime))` was very useful in doing so. – jmoorhead Jul 28 '20 at 12:58
  • Happy to help @jmoorhead :) – saranjeet singh Jul 28 '20 at 13:43

1 Answers1

1

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

saranjeet singh
  • 868
  • 6
  • 17