我正在运行 lambda,它将过滤掉正在运行的 ec2 实例并使用 HTTP 发布请求将有效负载发送到 slack 通道,当我运行代码时,它会过滤掉输出中的正在运行的实例,但它在执行时显示 LocationParseError。如何解决这个错误?
import json
import boto3
import logging
import os
import urllib3
import urllib.parse
from urllib3.util import parse_url
from urllib3.exceptions import (
DecodeError, ReadTimeoutError, ProtocolError, LocationParseError)
#from urlparse import parse_qs
from boto3 import resource
ec2 = boto3.resource('ec2')
region = 'us-east-1'
def lambda_handler(event, context):
#print(json.dumps(event))
ec2 = boto3.resource('ec2', region)
url = "https://hooks.slack.com/services/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"
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()
req = http.request(url, (instanceList), {'Content-Type': 'application/json'})
```