Deleting expired AWS Hybrid Activations

117 views Asked by At

The following code is based off of the boto3 / API documentation, it prints what should be deleted but doesn't delete the Hybrid activation, nor does it create an error. Can you help me determine why the activations aren't being deleted.

import boto3
client = boto3.client('ssm')
response = client.describe_activations(
    Filters=[
        {
            'FilterKey': 'IamRole',
            'FilterValues': [
                'MySSMServiceRole'
            ]
        }
    ]
)

print('\n  These Hybrid Activations were deleted:')
for x in response['ActivationList']:
    a = x['ActivationId']
    b = x['Description'][0:3]
    c = x['Expired']
    if c == 'True':
        delete_activation(
            {
                'ActivationList': a
            }
        )
    print('     {}  {}  {}'.format(a, b, c))

I originally was using this in attempts to to delete the expired activations but was getting the same result.

response = client.delete_activation(
    ActivationId = a
)
1

There are 1 answers

0
jmoorhead On BEST ANSWER

I changed the if statement to use the c variable and it worked. The original if statement was comparing a string to boolean, and why it didn't work.

if c:
    client.delete_activation(
        ActivationId = a
    )