feat(aws-lambda) add S3BatchEvent (#38142)

* add S3BatchEvent

* rename S3BatchEventResponseResultCodes

* linting

* s3VersionId is nullable

* add types for S3BatchHandler

* linting

* refactor S3Batch type names to conform to standard

* linting

* linting
This commit is contained in:
Peter McIntyre
2019-09-24 14:23:29 -07:00
committed by Michael Crane
parent 533c47930c
commit 4f95415cb5
2 changed files with 101 additions and 0 deletions
+56
View File
@@ -1274,3 +1274,59 @@ const lexEventHandler: AWSLambda.LexHandler = async (
str = context.functionName;
return lexResult;
};
/**
* S3 Batch Operations event
* https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html
*/
const S3BatchEvent: AWSLambda.S3BatchEvent = {
invocationSchemaVersion: '1.0',
invocationId: 'foo_invocation_id',
job: { id: 'foo_job_id' },
tasks: [
{
taskId: '11111',
s3Key: 'example.json',
s3BucketArn: 'arn:aws:s3:::foo-bucket',
s3VersionId: null,
},
{
taskId: '11111',
s3Key: 'example.json',
s3BucketArn: 'arn:aws:s3:::foo-bucket',
s3VersionId: 'asdf',
},
],
};
const S3BatchResult: AWSLambda.S3BatchResult = {
invocationSchemaVersion: '1.0',
treatMissingKeysAs: 'PermanentFailure',
invocationId: 'foo_invocation_id',
results: [{
taskId: '11111',
resultCode: 'Succeeded',
resultString: 'foo',
}, {
taskId: '22222',
resultCode: 'TemporaryFailure',
resultString: 'Error: failure',
}, {
taskId: '33333',
resultCode: 'PermanentFailure',
resultString: 'Error: failure',
}],
};
const S3BatchHandler: AWSLambda.S3BatchHandler = async (
event: AWSLambda.S3BatchEvent,
context: AWSLambda.Context,
) => {
// $ExpectType S3BatchEvent
event;
// $ExpectType Context
context;
str = context.functionName;
return S3BatchResult;
};
+45
View File
@@ -29,6 +29,7 @@
// Roberto Zen <https://github.com/skyzenr>
// Grzegorz Redlicki <https://github.com/redlickigrzegorz>
// Juan Carbonel <https://github.com/juancarbonel>
// Peter McIntyre <https://github.com/pwmcintyre>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -252,6 +253,47 @@ export interface S3Event {
}
export type S3CreateEvent = S3Event; // old name
/**
* S3 Batch Operations event
* https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html
*/
export interface S3BatchEvent {
invocationSchemaVersion: string;
invocationId: string;
job: S3BatchEventJob;
tasks: S3BatchEventTask[];
}
export interface S3BatchEventJob {
id: string;
}
export interface S3BatchEventTask {
taskId: string;
s3Key: string;
s3VersionId: string | null;
s3BucketArn: string;
}
export interface S3BatchResult {
invocationSchemaVersion: string;
treatMissingKeysAs: S3BatchResultResultCode;
invocationId: string;
results: S3BatchResultResult[];
}
export type S3BatchResultResultCode =
| 'Succeeded'
| 'TemporaryFailure'
| 'PermanentFailure';
export interface S3BatchResultResult {
taskId: string;
resultCode: S3BatchResultResultCode;
resultString: string;
}
/**
* Cognito User Pool event
* http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html
@@ -1127,4 +1169,7 @@ export type FirehoseTransformationHandler = Handler<FirehoseTransformationEvent,
export type CustomAuthorizerHandler = Handler<CustomAuthorizerEvent, CustomAuthorizerResult>;
export type CustomAuthorizerCallback = Callback<CustomAuthorizerResult>;
export type S3BatchHandler = Handler<S3BatchEvent, S3BatchResult>;
export type S3BatchCallback = Callback<S3BatchResult>;
export as namespace AWSLambda;