简体   繁体   English

Flink 无法向本地堆栈上的 S3 存储桶发送 http 请求

[英]Flink can not send http request to S3 bucket on localstack

I'm trying to call the getObject api to get an external file on S3 bucket0 within my Flink job, but it keeps getting a SdkException from my localstack setup:我正在尝试调用getObject api 以在我的 Flink 作业中获取 S3 bucket0 上的外部文件,但它不断从我的 localstack 设置中获取 SdkException:

 org.apache.flink.kinesis.shaded.com.amazonaws.SdkClientException:
 Unable to execute HTTP request: mybucketName.s3.localstack

This is how I created my resources with docker compose and localstack这就是我使用 docker compose 和 localstack 创建资源的方式

container_name: localstack
image: localstack/localstack:0.12.15
ports:
  - "14566:4566"
expose:
  - "4566"
environment:
  - DEFAULT_REGION=us-east-1
  - AWS_ACCESS_KEY_ID=test
  - AWS_SECRET_ACCESS_KEY=test
  - EDGE_PORT=4566
  - SERVICES=s3
  - AWS_CBOR_DISABLE=1

I have tried to replace the endpoint with http://localstack:4566 and http://s3.localstack:4566 , but I still see the error我尝试用 http://localstack:4566 和http://s3.localstack:4566替换端点,但我仍然看到错误

import org.apache.flink.kinesis.shaded.com.amazonaws.services.s3.AmazonS3ClientBuilder;
    
AwsClientBuilder.EndpointConfiguration endpointConfiguration =
        new AwsClientBuilder.EndpointConfiguration(
            "http://s3.localstack:4566",   // also tried localstack:4566 and 127.0.0.1:4566 etc..
            region);

s3Client = AmazonS3ClientBuilder.standard()
        .withEndpointConfiguration(endpointConfiguration)
        .build()


S3Object s3Object = s3Client.getObject(bucketName, objectLocation);

Anyone knows why I'm getting this issue?任何人都知道为什么我会遇到这个问题? Sorry the SdkException only shows unable to execute HTTP and does not output lots for context/info.抱歉,SdkException 仅显示无法执行 HTTP 而不是 output 很多上下文/信息。 Thank you.谢谢你。

I think I have found the solution, I should call.enablePathStyleAccess() in my client我想我已经找到了解决方案,我应该在我的客户端中调用 enablePathStyleAccess()

    AmazonS3ClientBuilder.standard()
        .withEndpointConfiguration(endpointConfiguration)
        .enablePathStyleAccess()
        .build()

Please refer to this post请参考这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM