How can I use a customized build of the AWS sdk in ReactJS?

你。 提交于 2019-12-11 06:42:49

问题


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


回答1:


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");


来源:https://stackoverflow.com/questions/49216662/how-can-i-use-a-customized-build-of-the-aws-sdk-in-reactjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!