Vignesh S
Vignesh S

Reputation: 429

Uncaught reference error: AWS not defined

I have been trying to implement DynamoDB using Javascript. When I used, AWS.config.update='my_region', I'm getting "uncaught referenceerror: AWS in not defined". I have declared AWS globally.

Note: aws.sdk.js has been implemented

Upvotes: 8

Views: 18553

Answers (5)

Vignesh S
Vignesh S

Reputation: 429

JAVASCRIPT

AWS.config.update='xx-xxxx-x'; //the aforementioned error(global variable)

var user={
            UserPoolId: 'xx-xxxx-x_xxxxxxxxx', 
            ClientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
        };

var data=new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(user);       

AWS.config.credentials = new AWS.CognitoIdentityCredentials({

IdentityPoolId: "xx-xxxx-x:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",

});

Upvotes: 0

Pratik
Pratik

Reputation: 1399

One Crucial Mistake I was doing is not to add
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script> this line in my html code(for front-end side in angular2). If you are using NodeJS then you have to add this file by using npm install aws-sdk.

You can find this information in this link.

Upvotes: 4

Vignesh S
Vignesh S

Reputation: 429

I have rectified it. Added the aws-sdk inside head tag instead of adding it in body tag

Upvotes: 1

Vignesh S
Vignesh S

Reputation: 429

HTML

    <script type="text/javascript" src="js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>
    <script type="text/javascript" src="js/min/aws-cognito-sdk.min.js"></script>
    <script type="text/javascript" src="js/min/amazon-cognito-identity.min.js"></script>
    <script type="text/javascript" src="js/min/sjcl.min.js"></script>

    <script type="text/javascript" src="js/min/moment.min.js"></script>
    <script type="text/javascript" src="js/src/jsbn.js"></script>
    <script type="text/javascript" src="js/src/jsbn2.js"></script>

Upvotes: 0

notionquest
notionquest

Reputation: 39186

If you are using node.js aws sdk, you should include the require.

var AWS = require("aws-sdk");
var creds = new AWS.Credentials('akid', 'secret', 'session');

AWS.config.update({
    region: "us-west-2",
    endpoint: "http://localhost:8000",
    credentials: creds
});

If you are using JavaScript in HTML, please include the SDK.

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

If the above solution doesn't resolve the issue, please show your full code to look at your scenario specifically.

Javascript Example

Upvotes: 13

Related Questions