我如何创建一个AWS Lambda函数来通知堆栈的所有者退出?

时间:2019-01-14 06:25:22

标签: amazon-web-services aws-lambda amazon-cloudformation boto3

我正在尝试为aws cloudformation创建一个lambda函数,该函数将采用retirementDate参数并通知用户堆栈的退出。 否则,如果不采取任何措施,则将'deadManSwitchDate'标签分配给堆栈。

我已经使用boto3获取了退休日期。我该如何进一步?

import boto3  
client = boto3.client('cloudformation')  
stack_list=['NonProd-MPCS-REG']  
for stackname in stack_list:  
    cf_details = client.describe_stacks(StackName = stackname)['Stacks']:  
     for parameters in cf_details:  
        for tag in parameters['Parameters']:  
            if tag['ParameterKey'] == 'RetirementDate':  
                print(tag['ParameterValue'])

更新

tag['ParameterValue']在字符串01/15/2019中,我试图将其转换为日期格式。

if tag['ParameterKey'] == 'DeadManSwitchDate':  
    retirement_date.append(tag['ParameterValue'])  
    for i in retirement_date:  
        dead_date=datetime.strptime('i','%d/%m/%Y').date()  

我收到以下错误:

  

文件“ /usr/local/lib/python3.5/_strptime.py”,第343行,在_strptime中       (data_string,格式)   ValueError:时间数据“ ParameterValue”与格式“%d /%m /%Y”不匹配

0 个答案:

没有答案