I think a more appropriate way to do this is
import { <ServiceName> } from 'aws-sdk';
for instance
import { DynamoDB } from 'aws-sdk';
followed by
this.client = new DynamoDB(); in the class.
I say it is more appropriate because it uses TypeScript's import syntax.
Also, there's a clear explanation - by AWS - on how to use TS with AWS SDK here.
Answer from Michael Pell on Stack Overflow
» npm install @aws-sdk/types
» npm install @types/aws-sdk
How do I use AWS sdk definitions for TypeScript?
Dealing with non-existent types in the aws-sdk for JS v3
aws sdk - converting types from aws sdk v2 to v3 (typescript) - Stack Overflow
Node.js SDK TypeScript
I think a more appropriate way to do this is
import { <ServiceName> } from 'aws-sdk';
for instance
import { DynamoDB } from 'aws-sdk';
followed by
this.client = new DynamoDB(); in the class.
I say it is more appropriate because it uses TypeScript's import syntax.
Also, there's a clear explanation - by AWS - on how to use TS with AWS SDK here.
Change to :
import AWS = require('aws-sdk');
var ses:AWS.SES = new AWS.SES();
Note: if import is unclear you probably want to read up on modules : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
TIP: always a good idea to see the test file for intended usage : https://github.com/borisyankov/DefinitelyTyped/blob/master/aws-sdk/aws-sdk-tests.ts
tl;dt I'm migrating code over to the recommended v3 aws-sdk for JS and there are some types that no longer exist in the model-generated @aws-sdk/client-<SERVICE> code
I'm migrating my project's code over to the recommended v3 aws-sdk for JS and there are some types (my project uses TS) that no longer exist in the model-generated @aws-sdk/client-<SERVICE> code. According to the official aws-sdk-js-v3 repo:
The v3 codebase is generated from internal AWS models that AWS services expose. We use smithy-typescript to generate all code in the /clients subdirectory. These packages always have a prefix of @aws-sdk/client-XXXX and are one-to-one with AWS services and service operations.
I've heard some frustration with the auto-generated code from coworkers, but this is the first time I've seen instances of the new v3 SDK differing from v2. We had previously been using types like:
import { StackName } from 'aws-sdk/clients/cloudformation';
which wasn't really an issue because it's just a string, but there are one's that get a bit trickier like:
import { RuleResponseList } from 'aws-sdk/clients/eventbridge';
which is itself an Array of Rules which are fairly complex and that I really do not want to type myself.
The v3 migration opts to completely remove imports from aws-sdk/* so I'm a bit stuck... is this an oversight and just something that needs to be brought to the AWS team's attention or am I missing how to import these types in v3?
Edit: a word & formatting
I am tasked with refactoring a node 12 typescript lambda service. I have bumped versions of node up to node 18 and am working to upgrade from aws-sdk v1 to v3. I am a little bit stuck, i've started installing aws packages like @aws-sdk/client-lambda and @aws-sdk/types. I can't find a definite answer to whether or not I still need @types/aws-lambda though, I haven't been able to find anything that say whether the lambda handler types for sns and sqs exist in @aws-sdk/types. I have very little experience with node and typescript and my team is short staffed so the DevOps guy(me) who usually handles my infrastructure, pipeline and deployment stuff is tasked with this. Any help, advice, links to good detailed docs would be appreciated. TYIA.
EDIT: I thought that because aws-sdk has the /types package I would use that for handler types. Seems that we should use the aws-lambda package for the handler types for typescript. I found it in this example from the second link in the topics section https://docs.aws.amazon.com/lambda/latest/dg/lambda-typescript.html