我有一个简单的Lambda函数,它的工作是使HTTP到达某个服务器。
我需要同时运行多个函数的副本(数百个),,并且我希望为来自每个Lambda的每个HTTP提供一个不同的源IP地址。
我的问题:
谢谢
阿维沙伊
至于问题2,我使用以下代码来调用Lambda函数的N个并发副本。
import boto3, json
from concurrent.futures import ThreadPoolExecutor
N = 5
unique_ips = set()
lambda_client = boto3.client('lambda', region_name='us-west-2')
def _lambda_caller(idx):
test_event = dict(idx=idx)
res = lambda_client.invoke(
FunctionName='SimpleHTTPGetter',
InvocationType='RequestResponse',
Payload=json.dumps(test_event),
)
data = json.loads(res['Payload']._raw_stream.data)
print('Thread {} is done'.format(idx))
unique_ips.add(data['body'])
with ThreadPoolExecutor(max_workers=N) as executor:
for i in range(0,N):
future = executor.submit(_lambda_caller,i)
executor.shutdown()
print('Done')我的Lambda代码(简写)
import json
import socket
def lambda_handler(event, context):
print('-- HTTP Client started')
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
print('My IP address is {}:'.format(ip))
return {
"statusCode": 200,
"body": ip
}发布于 2018-10-17 16:53:15
您需要创建一个VPC,确保您附加了一个允许访问internet的子网。然后将安全策略附加到您的lambda上。一步一步地在这里:https://medium.com/@philippholly/aws-lambda-enable-outgoing-internet-access-within-vpc-8dd250e11e12
https://stackoverflow.com/questions/52819436
复制相似问题