I have a lambda function which filters out running ec2 instances and stores them in an array, then it is sent as a payload to the slack channel. The problem is when I run the function it will not send the list but the print command will list it out on output.
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"})
```
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…