How to implement aws.sdk.ts file in Typescript?

I tried using the aws-sdk.ts file in the mainmodule.ts file below. But getting the error is undefined.

/// <reference path="aws.sdk.ts" />
import * as AWS from 'aws.sdk';
var typeScriptViewModel = function (first, last) {
    var self = this;
    AWS.Config({
        accessKeyId: 'ABC',
        secretAccessKey: 'ABCSECRET'
    });

    AWS.config.region = 'us-east-1'; 

   // many more usage of AWS. but got stuck on the first implementation itself.
   //var bucket = new AWS.S3({
   //         params: {
   //             Bucket: bucketName, Prefix: path, Delimiter: '/'
   //         }
   //     });
}

It throws the error message "Uncaught TypeError: Unable to read the" Config "property from undefined".

Can someone tell me how to use the s3 bucket using aws.sdk.ts? I am new to Typescript.

+4
source share
3 answers

Not quite sure if this is a problem, but your link should be:

/// <reference path="aws.sdk.d.ts" />

Instead:

/// <reference path="aws.sdk.ts" />

Then you can import:

import * as AWS from 'aws.sdk';

Make sure you install both type definitions:

$ typings install --global --save dt~aws-sdk

And npm module:

$ npm install --save aws-sdk

Update

typings.json awsdemo, packages.config ( Visual Studio .d.ts):

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="aws-sdk.TypeScript.DefinitelyTyped" version="1.9.4" targetFramework="net451" />
  <package id="node.TypeScript.DefinitelyTyped" version="3.0.0" targetFramework="net451" />
  <package id="RequireJS" version="2.2.0" targetFramework="net451" />
  <package id="requirejs.TypeScript.DefinitelyTyped" version="0.4.3" targetFramework="net451" />
</packages>

nuget typings, .

. , angular aws-sdk. (, es6-shim, ).

0

(.d.ts), , , :

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/aws-sdk

:

import * as AWS from 'aws-sdk';
var typeScriptViewModel = function (first, last) {
    const options = {
        accessKeyId: 'ABC',
        secretAccessKey: 'ABCSECRET',
        region: "us-east-1"
    };
    let s3 = new AWS.S3(options);

    // many more usage of AWS here
    // (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html)
    let params = {
        Bucket: 'STRING_VALUE' /* required */
    };
    s3.getBucketLocation(params, (err, data) => {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
    });
}
0

angular :

npm install aws-sdk --save

TypeScript , , :

npm install --save-dev @types/node
0

Source: https://habr.com/ru/post/1650581/


All Articles