mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
[@types/aws-lambda] Add SQS Event Source (#27334)
* feat: Add initial typings * feat: Add tests for SQS Event Source * fix: linting fixes
This commit is contained in:
committed by
Wesley Wigham
parent
43c1545b6e
commit
e3727a66d2
@@ -838,3 +838,60 @@ let customHandler: AWSLambda.Handler<CustomEvent, CustomResult> = (event, contex
|
||||
};
|
||||
|
||||
let kinesisStreamHandler: AWSLambda.KinesisStreamHandler = (event: AWSLambda.KinesisStreamEvent, context: AWSLambda.Context, cb: AWSLambda.Callback<void>) => { };
|
||||
|
||||
let SQSMessageHandler: AWSLambda.SQSHandler = (event: AWSLambda.SQSEvent, context: AWSLambda.Context, cb: AWSLambda.Callback<void>) => { };
|
||||
|
||||
// See https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-sqs
|
||||
const SQSEvent: AWSLambda.SQSEvent = {
|
||||
Records: [
|
||||
{
|
||||
messageId: "c80e8021-a70a-42c7-a470-796e1186f753",
|
||||
receiptHandle: "AQEBJQ+/u6NsnT5t8Q/VbVxgdUl4TMKZ5FqhksRdIQvLBhwNvADoBxYSOVeCBXdnS9P+",
|
||||
body: "{\"foo\":\"bar\"}",
|
||||
attributes: {
|
||||
ApproximateReceiveCount: "3",
|
||||
SentTimestamp: "1529104986221",
|
||||
SenderId: "594035263019",
|
||||
ApproximateFirstReceiveTimestamp: "1529104986230"
|
||||
},
|
||||
messageAttributes: {},
|
||||
md5OfBody: "9bb58f26192e4ba00f01e2e7b136bbd8",
|
||||
eventSource: "aws:sqs",
|
||||
eventSourceARN: "arn:aws:sqs:us-west-2:594035263019:NOTFIFOQUEUE",
|
||||
awsRegion: "us-west-2"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let SQSMessageLegacyAsyncHandler: AWSLambda.SQSHandler = async (
|
||||
event: AWSLambda.SQSEvent,
|
||||
context: AWSLambda.Context,
|
||||
cb: AWSLambda.Callback<void>,
|
||||
) => {
|
||||
// $ExpectType SQSEvent
|
||||
event;
|
||||
str = event.Records[0].messageId;
|
||||
anyObj = event.Records[0].body;
|
||||
// $ExpectType Context
|
||||
context;
|
||||
str = context.functionName;
|
||||
// $ExpectType Callback<void>
|
||||
cb;
|
||||
cb();
|
||||
cb(null);
|
||||
cb(new Error());
|
||||
};
|
||||
|
||||
let SQSMessageNode8AsyncHandler: AWSLambda.SQSHandler = async (
|
||||
event: AWSLambda.SQSEvent,
|
||||
context: AWSLambda.Context
|
||||
) => {
|
||||
// $ExpectType SQSEvent
|
||||
event;
|
||||
str = event.Records[0].messageId;
|
||||
anyObj = event.Records[0].body;
|
||||
// $ExpectType Context
|
||||
context;
|
||||
str = context.functionName;
|
||||
return;
|
||||
};
|
||||
|
||||
35
types/aws-lambda/index.d.ts
vendored
35
types/aws-lambda/index.d.ts
vendored
@@ -642,6 +642,39 @@ export interface KinesisStreamEvent {
|
||||
Records: KinesisStreamRecord[];
|
||||
}
|
||||
|
||||
// SQS
|
||||
// https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html#supported-event-source-sqs
|
||||
export interface SQSRecord {
|
||||
messageId: string;
|
||||
receiptHandle: string;
|
||||
body: string;
|
||||
attributes: SQSRecordAttributes;
|
||||
messageAttributes: SQSMessageAttributes;
|
||||
md5OfBody: string;
|
||||
eventSource: string;
|
||||
eventSourceARN: string;
|
||||
awsRegion: string;
|
||||
}
|
||||
|
||||
export interface SQSEvent {
|
||||
Records: SQSRecord[];
|
||||
}
|
||||
|
||||
export interface SQSRecordAttributes {
|
||||
ApproximateReceiveCount: string;
|
||||
SentTimestamp: string;
|
||||
SenderId: string;
|
||||
ApproximateFirstReceiveTimestamp: string;
|
||||
}
|
||||
export interface SQSMessageAttribute {
|
||||
Name: string;
|
||||
Type: string;
|
||||
Value: string;
|
||||
}
|
||||
export interface SQSMessageAttributes {
|
||||
[name: string]: SQSMessageAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS Lambda handler function.
|
||||
* http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
|
||||
@@ -686,6 +719,8 @@ export type SNSHandler = Handler<SNSEvent, void>;
|
||||
export type CognitoUserPoolTriggerHandler = Handler<CognitoUserPoolTriggerEvent>;
|
||||
// TODO: Different event/handler types for each event trigger so we can type the result?
|
||||
|
||||
export type SQSHandler = Handler<SQSEvent, void>;
|
||||
|
||||
// TODO: CognitoSync
|
||||
|
||||
export type CloudFormationCustomResourceHandler = Handler<CloudFormationCustomResourceEvent, void>;
|
||||
|
||||
Reference in New Issue
Block a user