我有一个lambda 函数,它过滤掉正在运行的 ec2 实例并将它们存储在一个数组中,然后将其作为有效负载发送到slack channel。问题是当我运行该函数时,它不会发送列表,但打印命令会在输出中列出它。
import json
import boto3
import logging
import os
import urllib3
import urllib.parse
#from urlparse import parse_qs
from boto3 import resource
ec2 = boto3.resource('ec2')
region = 'us-east-1'
def lambda_handler(event, context):
ec2 = boto3.resource('ec2', region)
url = "https://hooks.slack.com/services/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"
text = "hi"
filters = [
{
'Name': 'instance-state-name',
'Values': ['running']
}
]
instances = ec2.instances.filter(Filters = filters)
RunningInstances = []
for instance in instances:
RunningInstances.append(instance.id)
instanceList = json.dumps(RunningInstances)
#List out running ec2 instances
print(instanceList)
http = urllib3.PoolManager()
r = http.request("POST",
"https://hooks.slack.com/services/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",
body = json.dumps(instanceList),
headers = {"Content-Type":"application/json"})
```