使用 NGINX 作为 boto3 或 AWS cli 的自定义端点 url

问题描述 投票:0回答:0

嗨,这不是重复的,我在当前情况下遇到问题,我有一台 EC2 机器,在同一个 VPN 中,我创建了一个 AWS 客户端 VPN,以便 VPN 客户端在成功连接后可以 ping 并访问 ec2 机器 ip,现在我想以安全的方式访问 S3,这样它就可以跳过互联网,因为 vpn connectino 上没有互联网访问,只有 EC2 可以访问,所以按照this指南在 NGINX 后面托管 S3 然后我假设我可以打电话给我aws cli 在 VPN 后面的客户端设备中使用以下方式

aws s3 ls s3://my-bucket --endpoint-url http://ec2ip/s3

它也应该可以在 python3 boto 库中调用。

import boto3

session = boto3.session.Session()

s3_client = session.client(
    service_name='s3',
    endpoint_url='http://ec2ip/s3'
)

print(s3_client.list_buckets())

在 EC2 nginx 中,我放置了以下配置

location /s3/  {
      rewrite ^/s3/(.*) /$1 break;
      resolver 1.1.1.1;
      proxy_http_version     1.1;
      proxy_redirect off;
      proxy_set_header       Connection "";
      proxy_set_header       Authorization '';
      proxy_set_header       Host $bucket;
      proxy_set_header       X-Real-IP $remote_addr;
      proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_hide_header      x-amz-id-2;
      proxy_hide_header      x-amz-request-id;
      proxy_hide_header      x-amz-meta-server-side-encryption;
      proxy_hide_header      x-amz-server-side-encryption;
      proxy_hide_header      Set-Cookie;
      proxy_ignore_headers   Set-Cookie;
      proxy_intercept_errors on;
      add_header             Cache-Control max-age=31536000;
      proxy_pass             http://$bucket;
    }

但是当然,这整件事都行不通。

nginx amazon-s3 amazon-ec2 boto3 openvpn
© www.soinside.com 2019 - 2024. All rights reserved.