Trantor
Trantor

Reputation: 766

How to use AWS S3 in Aurelia browser application in Javascript/ES6?

I'm trying to use a (public access) AWS.S3 bucket in an aurelia application (all aurelia updates done recently). First, I installed the aws-sdk via npm, getting this line into my config.js:

"npm:[email protected]": { ....

After importing

import AWS from 'aws-sdk';

( I also tried

import * as AWS from 'aws-sdk';

before duncanhall's answer )

and calling

AWS.config = new AWS.Config();
AWS.config.accessKeyId = "";
AWS.config.secretAccessKey = "";
AWS.config.region = 'eu-central-1';

I just try this:

let bucket = new AWS.S3({params: {Bucket: bucketPath}});

getting a

"TypeError: AWS.S3 is not a constructor at Function .... "

I guess I'm missing something essential?

Big thanks for any hints.

EDIT:

Another attempt was to uninstall aws-sdk from npm, download it separately, put it into /scripts/ folder and load it via

<script src="scripts/aws-sdk.js"></script>

in my main index.html file. Still I become:

GET http://localhost:9000/dist/aws-sdk.js 404 (Not Found)
ERROR [app-router] Error: XHR error (404 Not Found) loading http://localhost:9000/dist/aws-sdk.js

Upvotes: 2

Views: 661

Answers (2)

Trantor
Trantor

Reputation: 766

OK, I got it. The simplest solution is to REMOVE all imports of aws-sdk in js-code and to use

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.4.5.min.js"></script>

in the main index.html ... . It just works.

Upvotes: 0

duncanhall
duncanhall

Reputation: 11431

The aws-sdk module exposes a single default object.

Try replacing your wildcard import statement with a single definition:

import AWS from 'aws-sdk'

Upvotes: 1

Related Questions