如何在ReactJS中使用AWS sdk的自定义版本? [英] How can I use a customized build of the AWS sdk in ReactJS?
问题描述
我在这里使用AWS开发工具包进行自定义构建:
我可以在Chrome网络控制台中看到自定义sdk版本的加载状态为200,这样看来可以。
有人可以建议我需要做什么吗?
谢谢
您不能将定制的AWS开发工具包内部版本作为模块导入。您需要将其链接为 /public/index.html
中的外部js文件:
< script src = PATH / TO / YOUR / CUSTOM / aws-sdk- {SDK_VERSION} .min.js>< / script>
然后,您可以访问全局变量 AWS
通过窗口
对象:
const AWS = window.AWS;
AWS.config.region = YOUR_BUCKET_REGION;
const bucket = new AWS.S3({
params:{
Bucket: YOUR_BUCKET_NAME
}
});
或者,除了链接到定制的SDK版本外,您还可以始终 npm install aws-sdk
,然后将单个AWS服务导入为:
const S3 = require( aws- sdk / clients / s3);
I make a customized build here of the AWS SDK:
https://sdk.amazonaws.com/builder/js/
I can't find any examples of how to use this in ReactJS. Can anyone please point me in the right direction?
I have tried putting this in my index.html
And in my ReactJS code replaced imoprt with var:
//import AWS from 'aws-sdk'
var AWS = require('aws-sdk')
But now my application does not even load - shows only the background image and does not load - absolutely zero shows in the Chrome console - no messages at all.
I can see in the Chrome network console that the custom sdk build is being loaded OK with a status 200 so that seems to be OK.
Can anyone suggest what I need to do please?
thanks
You cannot import a customized build of AWS SDK as a module. You'll need to link it as an external js file in /public/index.html
:
<script src="PATH/TO/YOUR/CUSTOM/aws-sdk-{SDK_VERSION}.min.js"></script>
Then, you can access the global variable AWS
via window
object:
const AWS = window.AWS;
AWS.config.region = "YOUR_BUCKET_REGION";
const bucket = new AWS.S3({
params: {
Bucket: "YOUR_BUCKET_NAME"
}
});
Alternatively, instead of linking to customized SDK builds, you can always npm install aws-sdk
and then import individual AWS services as:
const S3 = require("aws-sdk/clients/s3");
这篇关于如何在ReactJS中使用AWS sdk的自定义版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!