Trying to use AWS Amplify
with S3 Storage following this tutorial with the manual set up. I created an amplify-test.js
file as follows:
// import Amplify from 'aws-amplify';
var Amplify = require('aws-amplify');
console.log(Amplify)
Amplify.configure({
Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: 'my identity pool id',
// REQUIRED - Amazon Cognito Region
region: 'region',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'my user pool id',
// OPTIONAL - Amazon Cognito Web Client ID
userPoolWebClientId: 'XX-XXXX-X_abcd1234',
},
Storage: {
bucket: 's3 bucket', //REQUIRED - Amazon S3 bucket
region: 'XX-XXXX-X', //OPTIONAL - Amazon service region
}
});
Amplify.Storage.put('test.txt', 'Hello')
.then (result => console.log(result))
.catch(err => console.log(err));
But when I run node amplify-test.js
, I got the following error:
Amplify.configure({ ^
TypeError: Amplify.configure is not a function at Object. (C:\Users\Xiaoyun\VuePwa\aws-cognito-amplify-test\src\amplify-test.js:6:9) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
I've already installed aws-amplify
by running npm install aws-amplify --save
. What am I doing wrong?
amplify configure will ask you to sign into the AWS Console. Once you're signed in, Amplify CLI will ask you to create an IAM user. Amazon IAM (Identity and Access Management) enables you to manage users and user permissions in AWS. You can learn more about Amazon IAM here.
General configuration The Amplify. configure() configuration can generally be included in your project entrypoint file (i.e. /src/main. js).
AWS Amplify is a tool developed by Amazon Web Services that helps make app development easier. It includes loads of features which allow you to quickly and easily work with other AWS services. This means you can spend more time building the features that make your app unique.
If you are using const Amplify = require("aws-amplify")
;
With
Amplify.default.configure({ Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: 'my identity pool id',
// REQUIRED - Amazon Cognito Region
region: 'region',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'my user pool id',
// OPTIONAL - Amazon Cognito Web Client ID
userPoolWebClientId: 'XX-XXXX-X_abcd1234',
},
Storage: {
bucket: 's3 bucket', //REQUIRED - Amazon S3 bucket
region: 'XX-XXXX-X', //OPTIONAL - Amazon service region
}
});
should solve your problem. It did for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With