aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.96k stars 557 forks source link

What are the counterparts for types such as APIGatewayProxyEvent, DynamoDBStreamEvent etc. in v3? #6094

Closed jepetko closed 1 month ago

jepetko commented 1 month ago

Describe the issue

(Note that this question was posted in "Discussions" more than 1 year ago and is unanswered until now, see https://github.com/aws/aws-sdk-js-v3/discussions/4572. Thus, I am re-posting it as a documentation issue.)


Dear colleagues,

I am struggling with finding the counterpart event types in the new implementation. I want to import types in lambda handlers such as

// version 2
import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from 'aws-lambda';

but I am not able to find it anywhere. Please can you provide more information about the proper typings for lambda invocations and other types of events?

I also hope to get some feedback on how I migrated DynamoDBStream and CloudWatch events, as it took me long to find it and I am even not sure it is correct.

For example, I migrated DynamoDB Stream event like this as the type has the same structure:

import {DynamoDBStreamEvent} from 'aws-lambda';

exports.onDbEvent = async (evt: DynamoDBStreamEvent) => {
// ....
};

exports.onDbEvent = async (evt: GetRecordsOutput) => { // .... };


Another issue was to find the proper **CloudWatch event** type. This is how I handled it (unfortunately I failed finding the equivalent types for Context and Callback, see below):

* BEFORE (v2):

```javascript
import {Callback, Context, EventBridgeEvent} from 'aws-lambda';

exports.onCloudWatchEvent = async (event: EventBridgeEvent<string, any>, context: Context, callback: Callback) => {
// ...
  callback(null, 'Finished');
};
import {PutEventsRequestEntry} from '@aws-sdk/client-cloudwatch-events';

exports.onCloudWatchEvent = async (evt: PutEventsRequestEntry, context: any, callback: (...args: any[]) => void) => {
// ...
  callback(null, 'Finished');
};

Could you provide information about where to find all those types? As a workaround, I copied the types from the old implementation which I would like to remove.

Thank you.

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/lambda/

RanVaknin commented 1 month ago

Hi @jepetko ,

the aws-lambda package is not related to the AWS SDK. The aws-sdk/client-lambda package is a control plane API that lets you create, update, and invoke your lambda function. I'm not too familiar with aws-lambda package, but this is not a part of the AWS SDK, and therefore should not be related to the JS SDK's migration from v2 to v3. AFAIK aws-lambda is the client for the data-plane API of lambda, and is mainly revolving exposing types that you can use in your code which should be SDK version agnostic.

Is there anything specific stopping you from using the aws-lambda package with v3?

Thanks, Ran~

jepetko commented 1 month ago

Hi @RanVaknin !

thank you for the answer!

Which npm package do you mean by aws-lambda? Do you mean @types/aws-lambda? https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/aws-lambda

What I realized now is when I migrated to v3 ("@aws-sdk/*": "^3.*.*"), I removed both, "aws-sdk": "^2.*.*" and "@types/aws-lambda": "^*.*.*" in the expectation that the types will be served by @aws-sdk/*. So the way to go is to take the types unrelated to the internal implementation of aws-sdk (such as events coming from SQS, API GW etc.) from @types/aws-lambda, correct?

Thanks!

RanVaknin commented 1 month ago

Hi @jepetko ,

Which npm package do you mean by aws-lambda? Do you mean @types/aws-lambda? https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/aws-lambda

I'm referring to the imports shared in your initial code:

import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from 'aws-lambda';

@types/aws-lambda is not a package maintained by AWS and has nothing to do with the SDK therefore it should not be related to the migration between v2 and v3. If there is an issue with the compatibility with v3, I suggest you open an issue on that repo, since the SDK only officially supports AWS packages and not 3rd party tools.

My guess is that there is no issue and you can safely re-introduce those imports since they just seem like type definitions and should be safe to use regardless of SDK version.

All the best, Ran~

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.