【发布时间】:2018-07-19 07:01:28
【问题描述】:
我正在尝试通过 cloudformation 部署 lambda 函数(python 3),即使堆栈创建成功,我在部署后遇到代码对齐问题!
以下是部署前来自 cloudformation 模板的实际代码:
lambdaEbsFunction:
Type: "AWS::Lambda::Function"
Properties:
Code:
ZipFile: >
#!/usr/bin/env python
import boto3
import json
import logging
from __future__ import print_function
#setup simple logging for INFO.
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
#define the connection for EC2.
ec2 = boto3.resource('ec2', region_name="us-east-2")
def lambda_handler(event, context):
def tag_them(instance, detail):
tempTags=[]
v={}
for t in instance.tags:
#pull the name tag and add volume detail
if t['Key'] == 'Name':
v['Value'] = t['Value'] + " - " + str(detail)
v['Key'] = 'Name'
tempTags.append(v)
#append the wanted tags to EBS
elif t['Key'] == 'Owner':
print("[INFO]: Owner tag " + str(t))
tempTags.append(t)
elif t['Key'] == 'Environment':
print("[INFO]: Environment Tag " + str(t))
tempTags.append(t)
else:
print("[INFO]: Skip Tag - " + str(t))
print("[INFO] " + str(tempTags))
return(tempTags)
base_instances = ec2.instances.filter(
Filters = [
{
'Name': 'tag:Name',
'Values': ['Jenkins Server']
},
]
)
for instance in base_instances:
for vol in instance.volumes.all():
tag = vol.create_tags(Tags=tag_them(instance, vol.attachments[0]['Device']))
print("[INFO]: " + str(tag))
这是创建堆栈成功后控制台中的 lambda 函数!我在缩进或其他方面做错了什么吗?
【问题讨论】:
标签: python-3.x amazon-web-services aws-lambda amazon-cloudformation