node.js - 带有 AWS 开发工具包 Node.js 的自定义 S3 服务器的自签名证书错误
问题描述
我正在尝试连接到自定义 S3 服务器(不是基于 AWS)并创建存储桶。
在 Python 中使用以下代码有效:
session = boto3.session.Session()
s3res = session.resource(service_name='s3',
use_ssl=True,
verify=False,
aws_access_key_id='xxx',
aws_secret_access_key='xxx',
endpoint_url='https://xxx',
config=botocore_client_config)
但是,Node.js 中的以下代码不会:
const AWS = require("aws-sdk");
const https = require('https');
const S3 = new AWS.S3({
accessKeyId: 'xxx',
secretAccessKey: 'xxx',
endpoint: 'https://xxx/',
s3ForcePathStyle: true,
httpOptions: {
agent: new https.Agent({ rejectUnauthorized: false })
}
});
实际上,它在尝试创建存储桶时会导致以下错误:
{ NetworkingError: Protocol "http:" not supported. Expected "https:"
at new ClientRequest (_http_client.js:109:11)
at Object.request (http.js:41:10)
at features.constructor.handleRequest (/home/ec2-user/s3-tests/node_modules/aws-sdk/lib/http/node.js:42:23)
如果我删除自定义 https 代理,我会收到以下错误:
{ Error: self signed certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1048:34)
此外,设置process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
也无济于事。
解决方案
那是因为当您在 中指定agent
时httpOptions
,您使用了https
:
const https = require('https');
如果您不想要 ssl 版本,请http
改用:
const http = require('http');
const S3 = new AWS.S3({
accessKeyId: 'xxx',
secretAccessKey: 'xxx',
endpoint: 'https://xxx/',
s3ForcePathStyle: true,
httpOptions: {
agent: new http.Agent({ rejectUnauthorized: false })
}
});
推荐阅读
- react-native - 使用 React Native EXPO 分享到 Instagram 提要
- python - 如何从此元组中删除引号?我怎样才能使列表同质化
- arrays - Slurm 阵列采用双倍 CPU 比请求
- javascript - AWS Amplify 登录错误 - 登录错误... [TypeError: (0, _getRandomBase.default) 不是函数
- python - Pb 检索元组列表中的最大值
- excel - 检查重复项,然后复制重复项旁边的单元格
- jquery - 表中的 Ajax 表单在表的 ajax 重新加载后不提交
- reactjs - 反应日期范围选择器
- java - Android 服务未通知它已启动且 UI 间歇性锁定
- python - 在整个 pandas 数据帧上从零四舍五入