Using aws-sdk with angular2
But it keeps telling me that the module doesn't exist.
Update TypeScript and aws-sdk to latest. In your tsconfig make sure you have moduleResolution: node
. Now you can simply do:
import * as AWS from 'aws-sdk';
From the aws-sdk docs on NPM (https://www.npmjs.com/package/aws-sdk)
Usage with TypeScript
The AWS SDK for JavaScript bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.
Pre-requisites Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:
Use TypeScript v2.x
Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
npm install --save-dev @types/node
Your tsconfig.json
or jsconfig.json
includes 'dom' and 'es2015.promise' under compilerOptions.lib. See tsconfig.json
for an example.
In the Browser
To use the TypeScript definition files with the global AWS object in a front-end project, add the following line to the top of your JavaScript or Typescript file where you intend to use it or add it to your tsconfig 'types' or Declarations file:
/// <reference types="aws-sdk" />
This will provide support for the global AWS object.
Previous Answer
I found that if I added
{ src: 'aws-sdk/dist/aws-sdk', inject: 'libs' }
to the additional_deps in the project.config.ts (if your using angular2-seed) or just add
<script src="/node_modules/aws-sdk/dist/aws-sdk.js"></script>
to your index.html Then I could add
declare const AWS: any;
To any of the .ts files I needed, I have access to the AWS object. Not sure if this is a good solution however.