Importing AWS SDK in Angular 2 Application

半腔热情 提交于 2019-11-30 20:28:36
Andy

You need to:

npm install aws-sdk -S

Then make sure you have this type installed (if you are not sure, then just run the code below):

npm install --save-dev @types/node

Now in your src folder, you will find tsconfig.app.ts (make sure not to get confused with tsconfig.ts at the root).

types line is empty and looks like this prior to editing: "types": []. You need to edit it. The tsconfig.app.ts should look like this after you add "types": ["node"]:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
  "outDir": "../out-tsc/app",
  "module": "es2015",
  "baseUrl": "",
  "types": ["node"]
},
"exclude": [
  "test.ts",
  "**/*.spec.ts"
  ]
}

Now you can just

import * as AWS from 'aws-sdk';

I am currently working with AWS with angular as my frontend, and am using the same angular cognito quickstart project for my authentication and authorisation flow.

For installation, I used npm install aws-sdk --save

The aws-sdk is under dependencies' in my package.json:

"dependencies": {
    .......
    "aws-sdk": "^2.41.0",
    .......
}

If you are using angular cli, make sure you include the aws-sdk into your angular-cli.json

After these I used declare var AWS: any; And I am able to use the library without any problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!