在 Localstack 中部署时出现 "Could not connect to the endpoint URL" boto3 错误
Getting "Could not connect to the endpoint URL" Error with boto3 when deploying in Localstack
我正在使用 Localstack 来测试我在本地的更改。我的 lambda 函数应该执行 putObject 并在 s3 存储桶中创建对象。在 AWS 环境中直接测试时,该功能运行良好。但在 Localstack 中,它不起作用。我收到以下错误。
Could not connect to the endpoint URL:
"http://localhost:4572/doyouknowme/pokemon.jpeg"
raise EndpointConnectionError(endpoint_url=request.url, error=e)ponset_exceptionlhost:4572/doyouknowme/pokemon.jpeg"
AWS 凭证:
[default]
aws_access_key_id = AKI****************
aws_secret_access_key = gL************************
region = us-east-1
Lambda 函数代码:
import json
import urllib.parse
import boto3
import base64
print('Loading function')
# session = boto3.Session(profile_name='personal')
# s3 = session.client('s3', endpoint_url='http://localhost:4574')
s3 = boto3.client('s3', endpoint_url='http://localhost:4572', region_name='us-east-1')
def lambda_handler(event, context):
# raise Exception('Something went wrong')
print("Received event: " + json.dumps(event, indent=2))
try:
image_data = base64.b64decode(event['image_data'])
response = s3.put_object(
Body=image_data,
Bucket='doyouknowme',
Key='pokemon.jpeg',
ContentType='image/jpeg'
)
print(response)
return response
except Exception as e:
print(e)
# print(
# 'Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as '
# 'this function.'.format(
# key, bucket))
raise e
我不确定为什么 s3 密钥附加到 lambda 访问的端点 URL。
感谢您帮助解决此问题。
对于遇到此问题的任何人:我在另一个 Docker 尝试使用 http://localhost:4566
访问 localstack
时遇到了它 boto3
。
我通过在我的 boto3 会话客户端中将 http://host.docker.internal:4566
作为我的 endpoint-url
解决了我的问题。
希望这对某人有所帮助!
我正在使用 Localstack 来测试我在本地的更改。我的 lambda 函数应该执行 putObject 并在 s3 存储桶中创建对象。在 AWS 环境中直接测试时,该功能运行良好。但在 Localstack 中,它不起作用。我收到以下错误。
Could not connect to the endpoint URL: "http://localhost:4572/doyouknowme/pokemon.jpeg" raise EndpointConnectionError(endpoint_url=request.url, error=e)ponset_exceptionlhost:4572/doyouknowme/pokemon.jpeg"
AWS 凭证:
[default]
aws_access_key_id = AKI****************
aws_secret_access_key = gL************************
region = us-east-1
Lambda 函数代码:
import json
import urllib.parse
import boto3
import base64
print('Loading function')
# session = boto3.Session(profile_name='personal')
# s3 = session.client('s3', endpoint_url='http://localhost:4574')
s3 = boto3.client('s3', endpoint_url='http://localhost:4572', region_name='us-east-1')
def lambda_handler(event, context):
# raise Exception('Something went wrong')
print("Received event: " + json.dumps(event, indent=2))
try:
image_data = base64.b64decode(event['image_data'])
response = s3.put_object(
Body=image_data,
Bucket='doyouknowme',
Key='pokemon.jpeg',
ContentType='image/jpeg'
)
print(response)
return response
except Exception as e:
print(e)
# print(
# 'Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as '
# 'this function.'.format(
# key, bucket))
raise e
我不确定为什么 s3 密钥附加到 lambda 访问的端点 URL。 感谢您帮助解决此问题。
对于遇到此问题的任何人:我在另一个 Docker 尝试使用 http://localhost:4566
访问 localstack
时遇到了它 boto3
。
我通过在我的 boto3 会话客户端中将 http://host.docker.internal:4566
作为我的 endpoint-url
解决了我的问题。
希望这对某人有所帮助!