aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

how can I use aws-sdk in typescript

Open ducduongtmb opened this issue 10 years ago • 3 comments

I used typescript ( tsx ) for react . In upload image task , I used aws-sdk to upload to server s3 . I also installed aws-sdk by npm and typings .

UploadFile.tsx

import * as AWS from 'aws-sdk';
//constant
import DefaultValue from '../../Constants/DefaultValue';

AWS.config.update({
    region: DefaultValue.REGION,
    credentials: new AWS.Credentials(DefaultValue.ACCESS_KEY_ID, DefaultValue.SECRET_KEY)
});

class UploadFile extends React.Component<any,any> {
    s3: any;
    constructor() {
        super();

        this.s3 = new AWS.S3({apiVersion: '2016-11-07'});
    }

}

Chrome console error : 'AWS is undefined' . how can i import AWS ? thanks for help .

ducduongtmb avatar Nov 07 '16 04:11 ducduongtmb

@ducduongtmb Are you using a tool like webpack or browserify to bundle your code, or are you including the SDK by adding a script tag to your page?

chrisradek avatar Nov 07 '16 17:11 chrisradek

You should be able to use the following when using a tool like webpack or browserify (or in node.js):

import AWS = require('aws-sdk');

Otherwise if you're including the SDK with a script tag, AWS should be available as a global variable. For type information, if you're using typescript 2.x, you can include this comment at the top of your JS file:

/// <reference types="aws-sdk" />

chrisradek avatar Nov 28 '16 17:11 chrisradek

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

lock[bot] avatar Sep 28 '19 17:09 lock[bot]