簡體   English   中英

從 localstack 訪問 S3 時,sam local invoke 獲取 connectionRefused

[英]sam local invoke gets connectionRefused when accessing S3 from localstack

我在創建 s3 存儲桶的地方運行 localstack。 但是,當我使用 SAM 調用 lambda function 列出存儲桶時,連接被拒絕。

我開始本地堆棧

localstack start

然后我使用 python 腳本創建並列出一個存儲桶:

import boto3

BUCKET_NAME = "mybucket"
HOST_ADDRESS= "http://localhost:4566"

s3_client = boto3.client('s3', region_name='us-east-1', endpoint_url=HOST_ADDRESS)

s3_client.create_bucket(Bucket=BUCKET_NAME)

然后我列出桶

import boto3

s3_client = boto3.client('s3', endpoint_url="http://localhost:4566")

for bucket in s3_client.list_buckets()["Buckets"]:
    print(bucket['Name'])

現在我調用我的 lambda function ,它與sam buildsam local invoke --profile=localstack做完全相同的事情。 配置文件 localstack 包含我的 localstack 的憑據和區域。 代碼是

#!/usr/bin/python3
import boto3

HOST_ADDRESS= "http://localhost:4566"

s3_client = boto3.client('s3', endpoint_url=HOST_ADDRESS)

def lambda_handler(event, context):
    s3_client.list_buckets()
    return { "statusCode": 200 }

模板:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'

Description: Lambda that reads from an s3 bucket

Resources:
  FetchFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      FunctionName: bucketFetchSAM
      Handler: app.lambda_handler
      Runtime: python3.8
      CodeUri: fetch_new/
      Timeout: 20
      Policies:
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - 's3:ListAllMyBuckets'
              Resource: '*'

這會產生以下錯誤消息

START RequestId: 24050f46-f66c-4916-a082-b7f5ce2deda7 Version: $LATEST
    raise EndpointConnectionError(endpoint_url=request.url, error=e)ponset_exceptionlhost:4566/"
{
    "errorMessage": "Could not connect to the endpoint URL: \"http://localhost:4566/\"",
    "errorType": "EndpointConnectionError",
    "stackTrace": [
        "  File \"/var/task/app.py\", line 13, in lambda_handler\n    s3_client.list_buckets()\n",
        "  File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
        "  File \"/var/runtime/botocore/client.py\", line 705, in _make_api_call\n    http, parsed_response = self._make_request(\n",
        "  File \"/var/runtime/botocore/client.py\", line 725, in _make_request\n    return self._endpoint.make_request(operation_model, request_dict)\n",
        "  File \"/var/runtime/botocore/endpoint.py\", line 104, in make_request\n    return self._send_request(request_dict, operation_model)\n",
        "  File \"/var/runtime/botocore/endpoint.py\", line 138, in _send_request\n    while self._needs_retry(attempts, operation_model, request_dict,\n",
        "  File \"/var/runtime/botocore/endpoint.py\", line 254, in _needs_retry\n    responses = self._event_emitter.emit(\n",
        "  File \"/var/runtime/botocore/hooks.py\", line 357, in emit\n    return self._emitter.emit(aliased_event_name, **kwargs)\n",
        "  File \"/var/runtime/botocore/hooks.py\", line 228, in emit\n    return self._emit(event_name, kwargs)\n",
        "  File \"/var/runtime/botocore/hooks.py\", line 211, in _emit\n    response = handler(**kwargs)\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 183, in __call__\n    if self._checker(attempts, response, caught_exception):\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 250, in __call__\n    should_retry = self._should_retry(attempt_number, response,\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 277, in _should_retry\n    return self._checker(attempt_number, response, caught_exception)\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 316, in __call__\n    checker_response = checker(attempt_number, response,\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 222, in __call__\n    return self._check_caught_exception(\n",
        "  File \"/var/runtime/botocore/retryhandler.py\", line 359, in _check_caught_exception\n    raise caught_exception\n",
        "  File \"/var/runtime/botocore/endpoint.py\", line 201, in _do_get_response\n    http_response = self._send(request)\n",
        "  File \"/var/runtime/botocore/endpoint.py\", line 270, in _send\n    return self.http_session.send(request)\n",
        "  File \"/var/runtime/botocore/httpsession.py\", line 438, in send\n    raise EndpointConnectionError(endpoint_url=request.url, error=e)\n"
    ]
}
END RequestId: 24050f46-f66c-4916-a082-b7f5ce2deda7

我特別困惑,因為我正在使用的命令在 sam 外部使用時顯然有效,但在 sam 內部似乎找不到或無法訪問存儲桶,或者缺少身份驗證。

當我放

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

進入 lambda 代碼我得到這些日志:

[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-parameter-build.s3.ListBuckets: calling handler <function validate_bucket_name at 0x7f2c32b7a820>
[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3RegionRedirector.redirect_from_cache of <botocore.utils.S3RegionRedirector object at 0x7f2c317b1910>>
[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3ArnParamHandler.handle_arn of <botocore.utils.S3ArnParamHandler object at 0x7f2c317b19d0>>
[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-parameter-build.s3.ListBuckets: calling handler <function generate_idempotent_uuid at 0x7f2c32b7a670>
[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-call.s3.ListBuckets: calling handler <function add_expect_header at 0x7f2c32b7ab80>
[DEBUG] 2022-09-10T11:37:48.729Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-call.s3.ListBuckets: calling handler <bound method S3RegionRedirector.set_request_url of <botocore.utils.S3RegionRedirector object at 0x7f2c317b1910>>
[DEBUG] 2022-09-10T11:37:48.730Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-call.s3.ListBuckets: calling handler <function inject_api_version_header_if_needed at 0x7f2c32b81ee0>
[DEBUG] 2022-09-10T11:37:48.730Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Making request for OperationModel(name=ListBuckets) with params: {'url_path': '/', 'query_string': '', 'method': 'GET', 'headers': {'User-Agent': 'Boto3/1.20.32 Python/3.8.13 Linux/5.15.0-46-generic exec-env/AWS_Lambda_python3.8 Botocore/1.23.32'}, 'body': b'', 'url': 'http://localhost:4566/', 'context': {'client_region': 'us-east-1', 'client_config': <botocore.config.Config object at 0x7f2c3259f9a0>, 'has_streaming_input': False, 'auth_type': None, 'signing': {'bucket': None}}}
[DEBUG] 2022-09-10T11:37:48.730Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event request-created.s3.ListBuckets: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f2c3259f9d0>>
[DEBUG] 2022-09-10T11:37:48.730Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event choose-signer.s3.ListBuckets: calling handler <bound method S3EndpointSetter.set_signer of <botocore.utils.S3EndpointSetter object at 0x7f2c317b1a60>>
[DEBUG] 2022-09-10T11:37:48.731Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event choose-signer.s3.ListBuckets: calling handler <bound method ClientCreator._default_s3_presign_to_sigv2 of <botocore.client.ClientCreator object at 0x7f2c32ba3b80>>
[DEBUG] 2022-09-10T11:37:48.731Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event choose-signer.s3.ListBuckets: calling handler <function set_operation_specific_signer at 0x7f2c32b7a550>
[DEBUG] 2022-09-10T11:37:48.731Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event before-sign.s3.ListBuckets: calling handler <bound method S3EndpointSetter.set_endpoint of <botocore.utils.S3EndpointSetter object at 0x7f2c317b1a60>>
[DEBUG] 2022-09-10T11:37:48.731Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Using S3 path style addressing.
[DEBUG] 2022-09-10T11:37:48.732Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Calculating signature using v4 auth.
[DEBUG] 2022-09-10T11:37:48.732Z    3b4786a3-2b51-4213-8611-d6ff374211a2    CanonicalRequest:
GET
/

host:localhost:4566
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20220910T113748Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
[DEBUG] 2022-09-10T11:37:48.732Z    3b4786a3-2b51-4213-8611-d6ff374211a2    StringToSign:
AWS4-HMAC-SHA256
20220910T113748Z
20220910/us-east-1/s3/aws4_request
745622b7535d6b3346127386c068f1ada28987a487193b43981e6ca68e719eb3
[DEBUG] 2022-09-10T11:37:48.732Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Signature:
ffe5af8ae43d86e0dff2c991546d722f70f886d8b49565467a607b20ef433042
[DEBUG] 2022-09-10T11:37:48.732Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=http://localhost:4566/, headers={'User-Agent': b'Boto3/1.20.32 Python/3.8.13 Linux/5.15.0-46-generic exec-env/AWS_Lambda_python3.8 Botocore/1.23.32', 'X-Amz-Date': b'20220910T113748Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=test/20220910/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=ffe5af8ae43d86e0dff2c991546d722f70f886d8b49565467a607b20ef433042'}>
[DEBUG] 2022-09-10T11:37:48.733Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Starting new HTTP connection (1): localhost:4566
[DEBUG] 2022-09-10T11:37:48.737Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Exception received when sending HTTP request.
Traceback (most recent call last):
  File "/var/task/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/var/task/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/var/task/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/runtime/botocore/httpsession.py", line 409, in send
    urllib_response = conn.urlopen(
  File "/var/task/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/var/task/urllib3/util/retry.py", line 525, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/var/task/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/var/task/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/var/task/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/var/task/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/var/lang/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/var/runtime/botocore/awsrequest.py", line 92, in _send_request
    rval = super(AWSConnection, self)._send_request(
  File "/var/lang/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/var/lang/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/var/runtime/botocore/awsrequest.py", line 120, in _send_output
    self.send(msg)
  File "/var/runtime/botocore/awsrequest.py", line 204, in send
    return super(AWSConnection, self).send(str)
  File "/var/lang/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/var/task/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/var/task/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPConnection object at 0x7f2c317e2100>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/runtime/botocore/endpoint.py", line 201, in _do_get_response
    http_response = self._send(request)
  File "/var/runtime/botocore/endpoint.py", line 270, in _send
    return self.http_session.send(request)
  File "/var/runtime/botocore/httpsession.py", line 438, in send
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localhost:4566/"[DEBUG] 2022-09-10T11:37:48.740Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Event needs-retry.s3.ListBuckets: calling handler <botocore.retryhandler.RetryHandler object at 0x7f2c317b18b0>
[DEBUG] 2022-09-10T11:37:48.741Z    3b4786a3-2b51-4213-8611-d6ff374211a2    retry needed, retryable exception caught: Could not connect to the endpoint URL: "http://localhost:4566/"
Traceback (most recent call last):
  File "/var/task/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/var/task/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/var/task/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/runtime/botocore/httpsession.py", line 409, in send
    urllib_response = conn.urlopen(
  File "/var/task/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/var/task/urllib3/util/retry.py", line 525, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/var/task/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/var/task/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/var/task/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/var/task/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/var/lang/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/var/runtime/botocore/awsrequest.py", line 92, in _send_request
    rval = super(AWSConnection, self)._send_request(
  File "/var/lang/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/var/lang/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/var/runtime/botocore/awsrequest.py", line 120, in _send_output
    self.send(msg)
  File "/var/runtime/botocore/awsrequest.py", line 204, in send
    return super(AWSConnection, self).send(str)
  File "/var/lang/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/var/task/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/var/task/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPConnection object at 0x7f2c317e2100>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/runtime/botocore/retryhandler.py", line 269, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/var/runtime/botocore/retryhandler.py", line 316, in __call__
    checker_response = checker(attempt_number, response,
  File "/var/runtime/botocore/retryhandler.py", line 222, in __call__
    return self._check_caught_exception(
  File "/var/runtime/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
  File "/var/runtime/botocore/endpoint.py", line 201, in _do_get_response
    http_response = self._send(request)
  File "/var/runtime/botocore/endpoint.py", line 270, in _send
    return self.http_session.send(request)
  File "/var/runtime/botocore/httpsession.py", line 438, in send
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localhost:4566/"[DEBUG] 2022-09-10T11:37:48.741Z    3b4786a3-2b51-4213-8611-d6ff374211a2    Retry needed, action of: 0.15278091352455614

片段[DEBUG] 2022-09-10T11:37:48.732Z 3b4786a3-2b51-4213-8611-d6ff374211a2 Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=http://localhost:4566/, headers={'User-Agent': b'Boto3/1.20.32 Python/3.8.13 Linux/5.15.0-46-generic exec-env/AWS_Lambda_python3.8 Botocore/1.23.32', 'X-Amz-Date': b'20220910T113748Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=test/20220910/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=ffe5af8ae43d86e0dff2c991546d722f70f886d8b49565467a607b20ef433042'}>確認已提交正確的地址和憑據。

我還找到了一種為我的本地腳本生成日志的方法,但我無法找出任何顯着差異:

2022-09-10 17:26:10,363 botocore.hooks [DEBUG] Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2022-09-10 17:26:10,365 botocore.hooks [DEBUG] Changing event name from before-call.apigateway to before-call.api-gateway
2022-09-10 17:26:10,366 botocore.hooks [DEBUG] Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2022-09-10 17:26:10,367 botocore.hooks [DEBUG] Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2022-09-10 17:26:10,367 botocore.hooks [DEBUG] Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2022-09-10 17:26:10,368 botocore.hooks [DEBUG] Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2022-09-10 17:26:10,369 botocore.hooks [DEBUG] Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2022-09-10 17:26:10,370 botocore.hooks [DEBUG] Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2022-09-10 17:26:10,371 botocore.hooks [DEBUG] Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2022-09-10 17:26:10,371 botocore.hooks [DEBUG] Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2022-09-10 17:26:10,371 botocore.hooks [DEBUG] Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2022-09-10 17:26:10,376 botocore.utils [DEBUG] IMDS ENDPOINT: http://169.254.169.254/
2022-09-10 17:26:10,377 botocore.credentials [DEBUG] Looking for credentials via: env
2022-09-10 17:26:10,377 botocore.credentials [DEBUG] Looking for credentials via: assume-role
2022-09-10 17:26:10,377 botocore.credentials [DEBUG] Looking for credentials via: assume-role-with-web-identity
2022-09-10 17:26:10,377 botocore.credentials [DEBUG] Looking for credentials via: sso
2022-09-10 17:26:10,377 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2022-09-10 17:26:10,378 botocore.credentials [INFO] Found credentials in shared credentials file: ~/.aws/credentials
2022-09-10 17:26:10,378 botocore.loaders [DEBUG] Loading JSON file: /home/.../sam_bucket_fetch/samvenv/lib/python3.8/site-packages/botocore/data/endpoints.json
2022-09-10 17:26:10,390 botocore.loaders [DEBUG] Loading JSON file: /home/.../sam_bucket_fetch/samvenv/lib/python3.8/site-packages/botocore/data/sdk-default-configuration.json
2022-09-10 17:26:10,390 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fa830c424c0>
2022-09-10 17:26:10,400 botocore.loaders [DEBUG] Loading JSON file: /home/.../sam_bucket_fetch/samvenv/lib/python3.8/site-packages/botocore/data/s3/2006-03-01/service-2.json
2022-09-10 17:26:10,408 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x7fa830cbcd30>
2022-09-10 17:26:10,408 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function lazy_call.<locals>._handler at 0x7fa830b7e160>
2022-09-10 17:26:10,422 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x7fa830cbcaf0>
2022-09-10 17:26:10,424 botocore.endpoint [DEBUG] Setting s3 timeout as (60, 60)
2022-09-10 17:26:10,424 botocore.loaders [DEBUG] Loading JSON file: /home/.../sam_bucket_fetch/samvenv/lib/python3.8/site-packages/botocore/data/_retry.json
2022-09-10 17:26:10,424 botocore.client [DEBUG] Registering retry handlers for service: s3
2022-09-10 17:26:10,425 botocore.hooks [DEBUG] Event before-parameter-build.s3.ListBuckets: calling handler <function validate_bucket_name at 0x7fa830c5cca0>
2022-09-10 17:26:10,425 botocore.hooks [DEBUG] Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3RegionRedirector.redirect_from_cache of <botocore.utils.S3RegionRedirector object at 0x7fa83039d6a0>>
2022-09-10 17:26:10,425 botocore.hooks [DEBUG] Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3ArnParamHandler.handle_arn of <botocore.utils.S3ArnParamHandler object at 0x7fa83039d760>>
2022-09-10 17:26:10,425 botocore.hooks [DEBUG] Event before-parameter-build.s3.ListBuckets: calling handler <function generate_idempotent_uuid at 0x7fa830c5caf0>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event before-call.s3.ListBuckets: calling handler <function add_expect_header at 0x7fa830c62040>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event before-call.s3.ListBuckets: calling handler <bound method S3RegionRedirector.set_request_url of <botocore.utils.S3RegionRedirector object at 0x7fa83039d6a0>>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event before-call.s3.ListBuckets: calling handler <function add_recursion_detection_header at 0x7fa830c5c790>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event before-call.s3.ListBuckets: calling handler <function inject_api_version_header_if_needed at 0x7fa830c5e3a0>
2022-09-10 17:26:10,426 botocore.endpoint [DEBUG] Making request for OperationModel(name=ListBuckets) with params: {'url_path': '/', 'query_string': '', 'method': 'GET', 'headers': {'User-Agent': 'Boto3/1.24.69 Python/3.8.10 Linux/5.15.0-46-generic Botocore/1.27.69'}, 'body': b'', 'url': 'http://localhost:4566/', 'context': {'client_region': 'us-east-1', 'client_config': <botocore.config.Config object at 0x7fa830544880>, 'has_streaming_input': False, 'auth_type': None, 'signing': {'bucket': None}}}
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event request-created.s3.ListBuckets: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7fa8305448b0>>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event choose-signer.s3.ListBuckets: calling handler <bound method S3EndpointSetter.set_signer of <botocore.utils.S3EndpointSetter object at 0x7fa83039d7f0>>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event choose-signer.s3.ListBuckets: calling handler <bound method ClientCreator._default_s3_presign_to_sigv2 of <botocore.client.ClientCreator object at 0x7fa830b7c9a0>>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event choose-signer.s3.ListBuckets: calling handler <function set_operation_specific_signer at 0x7fa830c5c9d0>
2022-09-10 17:26:10,426 botocore.hooks [DEBUG] Event before-sign.s3.ListBuckets: calling handler <bound method S3EndpointSetter.set_endpoint of <botocore.utils.S3EndpointSetter object at 0x7fa83039d7f0>>
2022-09-10 17:26:10,426 botocore.utils [DEBUG] Using S3 path style addressing.
2022-09-10 17:26:10,426 botocore.auth [DEBUG] Calculating signature using v4 auth.
2022-09-10 17:26:10,427 botocore.auth [DEBUG] CanonicalRequest:
GET
/

host:localhost:4566
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20220910T152610Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2022-09-10 17:26:10,427 botocore.auth [DEBUG] StringToSign:
AWS4-HMAC-SHA256
20220910T152610Z
20220910/us-east-1/s3/aws4_request
d92a569143f1a1e667c82b75387a5c934a1827c0fe066ad45d5456e68e611c0f
2022-09-10 17:26:10,427 botocore.auth [DEBUG] Signature:
cc00ece2c2d811961014abd7d8d94d89bf00bf79451984ed4d441d02f23aff74
2022-09-10 17:26:10,427 botocore.hooks [DEBUG] Event request-created.s3.ListBuckets: calling handler <function add_retry_headers at 0x7fa830c5ea60>
2022-09-10 17:26:10,427 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=http://localhost:4566/, headers={'User-Agent': b'Boto3/1.24.69 Python/3.8.10 Linux/5.15.0-46-generic Botocore/1.27.69', 'X-Amz-Date': b'20220910T152610Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=test/20220910/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=cc00ece2c2d811961014abd7d8d94d89bf00bf79451984ed4d441d02f23aff74', 'amz-sdk-invocation-id': b'bc337f23-16ed-45b4-a4fc-35ef791b8ca8', 'amz-sdk-request': b'attempt=1'}>
2022-09-10 17:26:10,427 urllib3.connectionpool [DEBUG] Starting new HTTP connection (1): localhost:4566
2022-09-10 17:26:10,437 urllib3.connectionpool [DEBUG] http://localhost:4566 "GET / HTTP/1.1" 200 None
2022-09-10 17:26:10,437 botocore.parsers [DEBUG] Response headers: {'Content-Type': 'application/xml; charset=utf-8', 'Server': 'Werkzeug/2.1.2 Python/3.10.6, hypercorn-h11', 'Date': 'Sat, 10 Sep 2022 15:26:10 GMT, Sat, 10 Sep 2022 15:26:10 GMT', 'x-amzn-requestid': 'OOV6T6D0GMR5UGEOFRVJZT7M4HERBJIRJU7KNCFOK8MA8W6WS6O3', 'Access-Control-Allow-Origin': '*', 'Connection': 'close', 'Last-Modified': 'Sat, 10 Sep 2022 15:26:10 GMT', 'x-amz-request-id': 'C1AC97638736B0D5', 'x-amz-id-2': 'MzRISOwyjmnupC1AC97638736B0D57/JypPGXLh0OVFGcJaaO3KW/hRAqKOpIEEp', 'accept-ranges': 'bytes', 'content-language': 'en-US', 'Transfer-Encoding': 'chunked'}
2022-09-10 17:26:10,437 botocore.parsers [DEBUG] Response body:
b'<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01"><Owner><ID>bcaf1ffd86f41161ca5fb16fd081034f</ID><DisplayName>webfile</DisplayName></Owner><Buckets><Bucket><Name>mybucket</Name><CreationDate>2022-09-10T10:46:41.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>'
2022-09-10 17:26:10,438 botocore.hooks [DEBUG] Event needs-retry.s3.ListBuckets: calling handler <botocore.retryhandler.RetryHandler object at 0x7fa83039d640>
2022-09-10 17:26:10,438 botocore.retryhandler [DEBUG] No retry needed.
2022-09-10 17:26:10,438 botocore.hooks [DEBUG] Event needs-retry.s3.ListBuckets: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7fa83039d6a0>>

localhost 將嘗試在容器內解析 lambda 當前正在運行的容器,localstack 在其自己的單獨容器中。

采用:

s3_client = boto3.client("s3",endpoint_url="http://host.docker.internal:4566")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM