From 47d306f0c0a2286cee6b78b285326212f0ff2ee4 Mon Sep 17 00:00:00 2001 From: Mike Dreyfus Date: Thu, 21 Jul 2022 03:52:00 -0700 Subject: [PATCH 1/3] chore(ecs-patterns) updating integration tests (#21260) A few integration tests slipped under the radar and were not updated with the new integ-tests library. Also corrected typos. Relates to: #21237 #21221 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...g.application-load-balanced-ecs-service.ts | 6 +- ...integ.network-load-balanced-ecs-service.ts | 12 +++- .../aws-ecs-integ.assets.json | 19 ----- .../aws-ecs-integ.template.json | 12 ++-- .../integ.json | 9 +-- .../manifest.json | 45 +++++++----- ...aultTestDeployAssert34DAD7DE.template.json | 1 + .../tree.json | 70 ++++++++++++++----- .../integ.l3-capacity-provider-strategies.ts | 5 ++ 9 files changed, 109 insertions(+), 70 deletions(-) delete mode 100644 packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.assets.json create mode 100644 packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE.template.json diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.application-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.application-load-balanced-ecs-service.ts index 61565f63432a9..5f4047b2b894b 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.application-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.application-load-balanced-ecs-service.ts @@ -2,7 +2,7 @@ import { AutoScalingGroup } from '@aws-cdk/aws-autoscaling'; import { InstanceType, Vpc } from '@aws-cdk/aws-ec2'; import { Cluster, ContainerImage, AsgCapacityProvider, EcsOptimizedImage } from '@aws-cdk/aws-ecs'; import { App, Stack } from '@aws-cdk/core'; - +import * as integ from '@aws-cdk/integ-tests'; import { ApplicationLoadBalancedEc2Service } from '../../lib'; const app = new App(); @@ -49,4 +49,8 @@ new ApplicationLoadBalancedEc2Service(stack, 'myService', { ], }); +new integ.IntegTest(app, 'applicationLoadBalancedEc2ServiceTest', { + testCases: [stack], +}); + app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.network-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.network-load-balanced-ecs-service.ts index eaeb198ff3af6..8e58254e35abb 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.network-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.network-load-balanced-ecs-service.ts @@ -2,14 +2,15 @@ import { AutoScalingGroup } from '@aws-cdk/aws-autoscaling'; import { InstanceType, Vpc } from '@aws-cdk/aws-ec2'; import { Cluster, ContainerImage, AsgCapacityProvider, EcsOptimizedImage } from '@aws-cdk/aws-ecs'; import { App, Stack } from '@aws-cdk/core'; - +import * as integ from '@aws-cdk/integ-tests'; import { NetworkLoadBalancedEc2Service } from '../../lib'; const app = new App(); const stack = new Stack(app, 'aws-ecs-integ'); const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 }); const cluster = new Cluster(stack, 'Cluster', { vpc }); -const provider1 = new AsgCapacityProvider(stack, 'FirstCapacityProvier', { + +const provider1 = new AsgCapacityProvider(stack, 'FirstCapacityProvider', { autoScalingGroup: new AutoScalingGroup(stack, 'FirstAutoScalingGroup', { vpc, instanceType: new InstanceType('t2.micro'), @@ -18,7 +19,8 @@ const provider1 = new AsgCapacityProvider(stack, 'FirstCapacityProvier', { capacityProviderName: 'first-capacity-provider', }); cluster.addAsgCapacityProvider(provider1); -const provider2 = new AsgCapacityProvider(stack, 'SecondCapacityProvier', { + +const provider2 = new AsgCapacityProvider(stack, 'SecondCapacityProvider', { autoScalingGroup: new AutoScalingGroup(stack, 'SecondAutoScalingGroup', { vpc, instanceType: new InstanceType('t3.micro'), @@ -49,4 +51,8 @@ new NetworkLoadBalancedEc2Service(stack, 'myService', { ], }); +new integ.IntegTest(app, 'networkLoadBalancedEc2ServiceTest', { + testCases: [stack], +}); + app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.assets.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.assets.json deleted file mode 100644 index 1c2d21178bb79..0000000000000 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.assets.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "20.0.0", - "files": { - "a7400ff8fc86ec26a5f93b426dc213bf2906ed87e3432b3256be777d370af33a": { - "source": { - "path": "aws-ecs-integ.template.json", - "packaging": "file" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "a7400ff8fc86ec26a5f93b426dc213bf2906ed87e3432b3256be777d370af33a.json", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.template.json index 861d99d59a7dc..341c11e7bf5df 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/aws-ecs-integ.template.json @@ -391,10 +391,10 @@ "Properties": { "CapacityProviders": [ { - "Ref": "FirstCapacityProvierD92F5AC4" + "Ref": "FirstCapacityProvider4F40D887" }, { - "Ref": "SecondCapacityProvierADE5DA56" + "Ref": "SecondCapacityProvider85378C3E" } ], "Cluster": { @@ -595,7 +595,7 @@ } } }, - "FirstCapacityProvierD92F5AC4": { + "FirstCapacityProvider4F40D887": { "Type": "AWS::ECS::CapacityProvider", "Properties": { "AutoScalingGroupProvider": { @@ -803,7 +803,7 @@ } } }, - "SecondCapacityProvierADE5DA56": { + "SecondCapacityProvider85378C3E": { "Type": "AWS::ECS::CapacityProvider", "Properties": { "AutoScalingGroupProvider": { @@ -997,14 +997,14 @@ { "Base": 1, "CapacityProvider": { - "Ref": "FirstCapacityProvierD92F5AC4" + "Ref": "FirstCapacityProvider4F40D887" }, "Weight": 1 }, { "Base": 0, "CapacityProvider": { - "Ref": "SecondCapacityProvierADE5DA56" + "Ref": "SecondCapacityProvider85378C3E" }, "Weight": 2 } diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/integ.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/integ.json index 4da317af1f94f..428a9945346f8 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/integ.json @@ -1,14 +1,11 @@ { "version": "20.0.0", "testCases": { - "ec2/integ.network-load-balanced-ecs-service": { + "networkLoadBalancedEc2ServiceTest/DefaultTest": { "stacks": [ "aws-ecs-integ" ], - "diffAssets": false, - "stackUpdateWorkflow": true + "assertionStack": "networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE" } - }, - "synthContext": {}, - "enableLookups": false + } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/manifest.json index 2785d3cfef415..814b078c1e8f1 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/manifest.json @@ -207,10 +207,10 @@ "data": "SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter" } ], - "/aws-ecs-integ/FirstCapacityProvier/FirstCapacityProvier": [ + "/aws-ecs-integ/FirstCapacityProvider/FirstCapacityProvider": [ { "type": "aws:cdk:logicalId", - "data": "FirstCapacityProvierD92F5AC4" + "data": "FirstCapacityProvider4F40D887" } ], "/aws-ecs-integ/SecondAutoScalingGroup/InstanceSecurityGroup/Resource": [ @@ -249,37 +249,28 @@ "data": "SecondAutoScalingGroupASG6483DDB2" } ], - "/aws-ecs-integ/SecondCapacityProvier/SecondCapacityProvier": [ + "/aws-ecs-integ/SecondCapacityProvider/SecondCapacityProvider": [ { "type": "aws:cdk:logicalId", - "data": "SecondCapacityProvierADE5DA56" + "data": "SecondCapacityProvider85378C3E" } ], "/aws-ecs-integ/myService/LB/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myServiceLB168895E1", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "myServiceLB168895E1" } ], "/aws-ecs-integ/myService/LB/PublicListener/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myServiceLBPublicListenerC78AE8A0", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "myServiceLBPublicListenerC78AE8A0" } ], "/aws-ecs-integ/myService/LB/PublicListener/ECSGroup/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myServiceLBPublicListenerECSGroup17E9BBC1", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "myServiceLBPublicListenerECSGroup17E9BBC1" } ], "/aws-ecs-integ/myService/LoadBalancerDNS": [ @@ -324,10 +315,19 @@ "data": "myServiceB0B6FAA0" } ], - "myServiceLBSecurityGroupFE0ED608": [ + "FirstCapacityProvierD92F5AC4": [ { "type": "aws:cdk:logicalId", - "data": "myServiceLBSecurityGroupFE0ED608", + "data": "FirstCapacityProvierD92F5AC4", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } + ], + "SecondCapacityProvierADE5DA56": [ + { + "type": "aws:cdk:logicalId", + "data": "SecondCapacityProvierADE5DA56", "trace": [ "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" ] @@ -335,6 +335,15 @@ ] }, "displayName": "aws-ecs-integ" + }, + "networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE.template.json", + "validateOnSynth": false + }, + "displayName": "networkLoadBalancedEc2ServiceTest/DefaultTest/DeployAssert" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE.template.json new file mode 100644 index 0000000000000..9e26dfeeb6e64 --- /dev/null +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/networkLoadBalancedEc2ServiceTestDefaultTestDeployAssert34DAD7DE.template.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/tree.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/tree.json index 03e6ada6d2a3e..6423a8c8a2508 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/network-load-balanced-ecs-service.integ.snapshot/tree.json @@ -9,7 +9,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.33" + "version": "10.1.49" } }, "aws-ecs-integ": { @@ -683,10 +683,10 @@ "aws:cdk:cloudformation:props": { "capacityProviders": [ { - "Ref": "FirstCapacityProvierD92F5AC4" + "Ref": "FirstCapacityProvider4F40D887" }, { - "Ref": "SecondCapacityProvierADE5DA56" + "Ref": "SecondCapacityProvider85378C3E" } ], "cluster": { @@ -993,13 +993,13 @@ "version": "0.0.0" } }, - "FirstCapacityProvier": { - "id": "FirstCapacityProvier", - "path": "aws-ecs-integ/FirstCapacityProvier", + "FirstCapacityProvider": { + "id": "FirstCapacityProvider", + "path": "aws-ecs-integ/FirstCapacityProvider", "children": { - "FirstCapacityProvier": { - "id": "FirstCapacityProvier", - "path": "aws-ecs-integ/FirstCapacityProvier/FirstCapacityProvier", + "FirstCapacityProvider": { + "id": "FirstCapacityProvider", + "path": "aws-ecs-integ/FirstCapacityProvider/FirstCapacityProvider", "attributes": { "aws:cdk:cloudformation:type": "AWS::ECS::CapacityProvider", "aws:cdk:cloudformation:props": { @@ -1298,13 +1298,13 @@ "version": "0.0.0" } }, - "SecondCapacityProvier": { - "id": "SecondCapacityProvier", - "path": "aws-ecs-integ/SecondCapacityProvier", + "SecondCapacityProvider": { + "id": "SecondCapacityProvider", + "path": "aws-ecs-integ/SecondCapacityProvider", "children": { - "SecondCapacityProvier": { - "id": "SecondCapacityProvier", - "path": "aws-ecs-integ/SecondCapacityProvier/SecondCapacityProvier", + "SecondCapacityProvider": { + "id": "SecondCapacityProvider", + "path": "aws-ecs-integ/SecondCapacityProvider/SecondCapacityProvider", "attributes": { "aws:cdk:cloudformation:type": "AWS::ECS::CapacityProvider", "aws:cdk:cloudformation:props": { @@ -1677,14 +1677,14 @@ "capacityProviderStrategy": [ { "capacityProvider": { - "Ref": "FirstCapacityProvierD92F5AC4" + "Ref": "FirstCapacityProvider4F40D887" }, "base": 1, "weight": 1 }, { "capacityProvider": { - "Ref": "SecondCapacityProvierADE5DA56" + "Ref": "SecondCapacityProvider85378C3E" }, "base": 0, "weight": 2 @@ -1736,6 +1736,42 @@ "fqn": "@aws-cdk/core.Stack", "version": "0.0.0" } + }, + "networkLoadBalancedEc2ServiceTest": { + "id": "networkLoadBalancedEc2ServiceTest", + "path": "networkLoadBalancedEc2ServiceTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "networkLoadBalancedEc2ServiceTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "networkLoadBalancedEc2ServiceTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.49" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "networkLoadBalancedEc2ServiceTest/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } } }, "constructInfo": { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-capacity-provider-strategies.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-capacity-provider-strategies.ts index 7f298449024a4..0057bc77bd3ec 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-capacity-provider-strategies.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-capacity-provider-strategies.ts @@ -1,6 +1,7 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as ecs from '@aws-cdk/aws-ecs'; import * as cdk from '@aws-cdk/core'; +import * as integ from '@aws-cdk/integ-tests'; import * as ecsPatterns from '../../lib'; const app = new cdk.App(); @@ -55,4 +56,8 @@ new ecsPatterns.NetworkLoadBalancedFargateService(stack, 'NLBFargateService', { ], }); +new integ.IntegTest(app, 'l3CapacityProviderStrategiesTest', { + testCases: [stack], +}); + app.synth(); From 76e0768f6d69b555925bb3c016861f517a01ecae Mon Sep 17 00:00:00 2001 From: Chinedum Echeta <60179183+cecheta@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:38:58 +0100 Subject: [PATCH 2/3] feat(lambda-event-sources): add AT_TIMESTAMP event source mapping starting position (#20741) Closes https://github.com/aws/aws-cdk/issues/17214 This PR adds `AT_TIMESTAMP` to the `StartingPosition` enum for lambda event source mappings. ---- ### All Submissions: * [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [X] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-lambda-event-sources/README.md | 3 +- .../aws-lambda-event-sources/lib/kinesis.ts | 13 +- .../aws-lambda-event-sources/package.json | 1 + .../test/integ.kinesis-at-timestamp.ts | 25 ++ ...aultTestDeployAssert8000E9DC.template.json | 1 + .../cdk.out | 1 + .../integ.json | 11 + ...-source-kinesis-at-timestamp.template.json | 150 +++++++++ .../manifest.json | 67 ++++ .../tree.json | 285 ++++++++++++++++++ .../test/kinesis.test.ts | 20 ++ .../aws-lambda/lib/event-source-mapping.ts | 24 +- .../test/event-source-mapping.test.ts | 35 ++- 13 files changed, 631 insertions(+), 5 deletions(-) create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis-at-timestamp.ts create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/AtTimestampDefaultTestDeployAssert8000E9DC.template.json create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/lambda-event-source-kinesis-at-timestamp.template.json create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/tree.json diff --git a/packages/@aws-cdk/aws-lambda-event-sources/README.md b/packages/@aws-cdk/aws-lambda-event-sources/README.md index ab00703b729bb..e9c34cd97bd45 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/README.md +++ b/packages/@aws-cdk/aws-lambda-event-sources/README.md @@ -196,7 +196,8 @@ behavior: * __onFailure__: In the event a record fails and consumes all retries, the record will be sent to SQS queue or SNS topic that is specified here * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. -* __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. +* __startingPosition__: Will determine where to being consumption. 'LATEST' will start at the most recent record and ignore all records that arrived prior to attaching the event source, 'TRIM_HORIZON' will start at the oldest record and ensure you process all available data, while 'AT_TIMESTAMP' will start reading records from a specified time stamp. Note that 'AT_TIMESTAMP' is only supported for Amazon Kinesis streams. +* __startingPositionTimestamp__: The time stamp from which to start reading. Used in conjunction with __startingPosition__ when set to 'AT_TIMESTAMP'. * __tumblingWindow__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/kinesis.ts index f0847429c5a45..207d47a33c59d 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/kinesis.ts @@ -4,6 +4,12 @@ import * as cdk from '@aws-cdk/core'; import { StreamEventSource, StreamEventSourceProps } from './stream'; export interface KinesisEventSourceProps extends StreamEventSourceProps { + /** + * The time from which to start reading, in Unix time seconds. + * + * @default - no timestamp + */ + readonly startingPositionTimestamp?: number; } /** @@ -11,9 +17,11 @@ export interface KinesisEventSourceProps extends StreamEventSourceProps { */ export class KinesisEventSource extends StreamEventSource { private _eventSourceMappingId?: string = undefined; + private startingPositionTimestamp?: number; constructor(readonly stream: kinesis.IStream, props: KinesisEventSourceProps) { super(props); + this.startingPositionTimestamp = props.startingPositionTimestamp; this.props.batchSize !== undefined && cdk.withResolved(this.props.batchSize, batchSize => { if (batchSize < 1 || batchSize > 10000) { @@ -24,7 +32,10 @@ export class KinesisEventSource extends StreamEventSource { public bind(target: lambda.IFunction) { const eventSourceMapping = target.addEventSourceMapping(`KinesisEventSource:${cdk.Names.nodeUniqueId(this.stream.node)}`, - this.enrichMappingOptions({ eventSourceArn: this.stream.streamArn }), + this.enrichMappingOptions({ + eventSourceArn: this.stream.streamArn, + startingPositionTimestamp: this.startingPositionTimestamp, + }), ); this._eventSourceMappingId = eventSourceMapping.eventSourceMappingId; diff --git a/packages/@aws-cdk/aws-lambda-event-sources/package.json b/packages/@aws-cdk/aws-lambda-event-sources/package.json index 1507af0534210..f741994a573ce 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/package.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/package.json @@ -72,6 +72,7 @@ }, "license": "Apache-2.0", "devDependencies": { + "@aws-cdk/integ-tests": "0.0.0", "@aws-cdk/assertions": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/integ-runner": "0.0.0", diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis-at-timestamp.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis-at-timestamp.ts new file mode 100644 index 0000000000000..d409d2c89bcd6 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis-at-timestamp.ts @@ -0,0 +1,25 @@ +import * as kinesis from '@aws-cdk/aws-kinesis'; +import * as lambda from '@aws-cdk/aws-lambda'; +import { App, Stack } from '@aws-cdk/core'; +import * as integ from '@aws-cdk/integ-tests'; +import { KinesisEventSource } from '../lib'; +import { TestFunction } from './test-function'; + +const app = new App(); + +const stack = new Stack(app, 'lambda-event-source-kinesis-at-timestamp'); + +const fn = new TestFunction(stack, 'F'); + +const stream = new kinesis.Stream(stack, 'S'); + +fn.addEventSource(new KinesisEventSource(stream, { + startingPosition: lambda.StartingPosition.AT_TIMESTAMP, + startingPositionTimestamp: 1655237653, +})); + +new integ.IntegTest(app, 'AtTimestamp', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/AtTimestampDefaultTestDeployAssert8000E9DC.template.json b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/AtTimestampDefaultTestDeployAssert8000E9DC.template.json new file mode 100644 index 0000000000000..9e26dfeeb6e64 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/AtTimestampDefaultTestDeployAssert8000E9DC.template.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..588d7b269d34f --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"20.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/integ.json b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/integ.json new file mode 100644 index 0000000000000..e350b22e588ff --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/integ.json @@ -0,0 +1,11 @@ +{ + "version": "20.0.0", + "testCases": { + "AtTimestamp/DefaultTest": { + "stacks": [ + "lambda-event-source-kinesis-at-timestamp" + ], + "assertionStack": "AtTimestampDefaultTestDeployAssert8000E9DC" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/lambda-event-source-kinesis-at-timestamp.template.json b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/lambda-event-source-kinesis-at-timestamp.template.json new file mode 100644 index 0000000000000..ad98ce2683890 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/lambda-event-source-kinesis-at-timestamp.template.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "FServiceRole3AC82EE1": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "FServiceRoleDefaultPolicy17A19BFA": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetRecords", + "kinesis:GetShardIterator", + "kinesis:ListShards", + "kinesis:ListStreams", + "kinesis:SubscribeToShard" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "S509448A1", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "FServiceRoleDefaultPolicy17A19BFA", + "Roles": [ + { + "Ref": "FServiceRole3AC82EE1" + } + ] + } + }, + "FC4345940": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" + }, + "Role": { + "Fn::GetAtt": [ + "FServiceRole3AC82EE1", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs14.x" + }, + "DependsOn": [ + "FServiceRoleDefaultPolicy17A19BFA", + "FServiceRole3AC82EE1" + ] + }, + "FKinesisEventSourcelambdaeventsourcekinesisattimestampSC3A1FFA33781E60D": { + "Type": "AWS::Lambda::EventSourceMapping", + "Properties": { + "FunctionName": { + "Ref": "FC4345940" + }, + "BatchSize": 100, + "EventSourceArn": { + "Fn::GetAtt": [ + "S509448A1", + "Arn" + ] + }, + "StartingPosition": "AT_TIMESTAMP", + "StartingPositionTimestamp": 1655237653 + } + }, + "S509448A1": { + "Type": "AWS::Kinesis::Stream", + "Properties": { + "RetentionPeriodHours": 24, + "ShardCount": 1, + "StreamEncryption": { + "Fn::If": [ + "AwsCdkKinesisEncryptedStreamsUnsupportedRegions", + { + "Ref": "AWS::NoValue" + }, + { + "EncryptionType": "KMS", + "KeyId": "alias/aws/kinesis" + } + ] + }, + "StreamModeDetails": { + "StreamMode": "PROVISIONED" + } + } + } + }, + "Conditions": { + "AwsCdkKinesisEncryptedStreamsUnsupportedRegions": { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-north-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-northwest-1" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..b6f363f4b3d5f --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/manifest.json @@ -0,0 +1,67 @@ +{ + "version": "20.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "lambda-event-source-kinesis-at-timestamp": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "lambda-event-source-kinesis-at-timestamp.template.json", + "validateOnSynth": false + }, + "metadata": { + "/lambda-event-source-kinesis-at-timestamp/F/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FServiceRole3AC82EE1" + } + ], + "/lambda-event-source-kinesis-at-timestamp/F/ServiceRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FServiceRoleDefaultPolicy17A19BFA" + } + ], + "/lambda-event-source-kinesis-at-timestamp/F/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FC4345940" + } + ], + "/lambda-event-source-kinesis-at-timestamp/F/KinesisEventSource:lambdaeventsourcekinesisattimestampSC3A1FFA3/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FKinesisEventSourcelambdaeventsourcekinesisattimestampSC3A1FFA33781E60D" + } + ], + "/lambda-event-source-kinesis-at-timestamp/S/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "S509448A1" + } + ], + "/lambda-event-source-kinesis-at-timestamp/AwsCdkKinesisEncryptedStreamsUnsupportedRegions": [ + { + "type": "aws:cdk:logicalId", + "data": "AwsCdkKinesisEncryptedStreamsUnsupportedRegions" + } + ] + }, + "displayName": "lambda-event-source-kinesis-at-timestamp" + }, + "AtTimestampDefaultTestDeployAssert8000E9DC": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "AtTimestampDefaultTestDeployAssert8000E9DC.template.json", + "validateOnSynth": false + }, + "displayName": "AtTimestamp/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/tree.json b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/tree.json new file mode 100644 index 0000000000000..109b939e6726c --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis-at-timestamp.integ.snapshot/tree.json @@ -0,0 +1,285 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.33" + } + }, + "lambda-event-source-kinesis-at-timestamp": { + "id": "lambda-event-source-kinesis-at-timestamp", + "path": "lambda-event-source-kinesis-at-timestamp", + "children": { + "F": { + "id": "F", + "path": "lambda-event-source-kinesis-at-timestamp/F", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "lambda-event-source-kinesis-at-timestamp/F/ServiceRole", + "children": { + "Resource": { + "id": "Resource", + "path": "lambda-event-source-kinesis-at-timestamp/F/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "lambda-event-source-kinesis-at-timestamp/F/ServiceRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "lambda-event-source-kinesis-at-timestamp/F/ServiceRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetRecords", + "kinesis:GetShardIterator", + "kinesis:ListShards", + "kinesis:ListStreams", + "kinesis:SubscribeToShard" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "S509448A1", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "FServiceRoleDefaultPolicy17A19BFA", + "roles": [ + { + "Ref": "FServiceRole3AC82EE1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnPolicy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Policy", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "lambda-event-source-kinesis-at-timestamp/F/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" + }, + "role": { + "Fn::GetAtt": [ + "FServiceRole3AC82EE1", + "Arn" + ] + }, + "handler": "index.handler", + "runtime": "nodejs14.x" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.CfnFunction", + "version": "0.0.0" + } + }, + "KinesisEventSource:lambdaeventsourcekinesisattimestampSC3A1FFA3": { + "id": "KinesisEventSource:lambdaeventsourcekinesisattimestampSC3A1FFA3", + "path": "lambda-event-source-kinesis-at-timestamp/F/KinesisEventSource:lambdaeventsourcekinesisattimestampSC3A1FFA3", + "children": { + "Resource": { + "id": "Resource", + "path": "lambda-event-source-kinesis-at-timestamp/F/KinesisEventSource:lambdaeventsourcekinesisattimestampSC3A1FFA3/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::EventSourceMapping", + "aws:cdk:cloudformation:props": { + "functionName": { + "Ref": "FC4345940" + }, + "batchSize": 100, + "eventSourceArn": { + "Fn::GetAtt": [ + "S509448A1", + "Arn" + ] + }, + "startingPosition": "AT_TIMESTAMP", + "startingPositionTimestamp": 1655237653 + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.CfnEventSourceMapping", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.EventSourceMapping", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.Function", + "version": "0.0.0" + } + }, + "S": { + "id": "S", + "path": "lambda-event-source-kinesis-at-timestamp/S", + "children": { + "Resource": { + "id": "Resource", + "path": "lambda-event-source-kinesis-at-timestamp/S/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Kinesis::Stream", + "aws:cdk:cloudformation:props": { + "retentionPeriodHours": 24, + "shardCount": 1, + "streamEncryption": { + "Fn::If": [ + "AwsCdkKinesisEncryptedStreamsUnsupportedRegions", + { + "Ref": "AWS::NoValue" + }, + { + "EncryptionType": "KMS", + "KeyId": "alias/aws/kinesis" + } + ] + }, + "streamModeDetails": { + "streamMode": "PROVISIONED" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-kinesis.CfnStream", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-kinesis.Stream", + "version": "0.0.0" + } + }, + "AwsCdkKinesisEncryptedStreamsUnsupportedRegions": { + "id": "AwsCdkKinesisEncryptedStreamsUnsupportedRegions", + "path": "lambda-event-source-kinesis-at-timestamp/AwsCdkKinesisEncryptedStreamsUnsupportedRegions", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnCondition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "AtTimestamp": { + "id": "AtTimestamp", + "path": "AtTimestamp", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "AtTimestamp/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "AtTimestamp/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.33" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "AtTimestamp/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis.test.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis.test.ts index e77fec71e5079..f42c0210786c8 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis.test.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/kinesis.test.ts @@ -263,4 +263,24 @@ describe('KinesisEventSource', () => { }); }); + + test('AT_TIMESTAMP starting position', () => { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const stream = new kinesis.Stream(stack, 'S'); + const eventSource = new sources.KinesisEventSource(stream, { + startingPosition: lambda.StartingPosition.AT_TIMESTAMP, + startingPositionTimestamp: 1640995200, + }); + + // WHEN + fn.addEventSource(eventSource); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { + StartingPosition: 'AT_TIMESTAMP', + StartingPositionTimestamp: 1640995200, + }); + }); }); diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 7840a465b87b2..c85dca2694db6 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -122,10 +122,17 @@ export interface EventSourceMappingOptions { * * @see https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#Kinesis-GetShardIterator-request-ShardIteratorType * - * @default - Required for Amazon Kinesis, Amazon DynamoDB, and Amazon MSK Streams sources. + * @default - no starting position */ readonly startingPosition?: StartingPosition; + /** + * The time from which to start reading, in Unix time seconds. + * + * @default - no timestamp + */ + readonly startingPositionTimestamp?: number; + /** * Allow functions to return partially successful responses for a batch of records. * @@ -299,6 +306,13 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp throw new Error(`tumblingWindow cannot be over 900 seconds, got ${props.tumblingWindow.toSeconds()}`); } + if (props.startingPosition === StartingPosition.AT_TIMESTAMP && !props.startingPositionTimestamp) { + throw new Error('startingPositionTimestamp must be provided when startingPosition is AT_TIMESTAMP'); + } + + if (props.startingPosition !== StartingPosition.AT_TIMESTAMP && props.startingPositionTimestamp) { + throw new Error('startingPositionTimestamp can only be used when startingPosition is AT_TIMESTAMP'); + } let destinationConfig; @@ -321,6 +335,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp eventSourceArn: props.eventSourceArn, functionName: props.target.functionName, startingPosition: props.startingPosition, + startingPositionTimestamp: props.startingPositionTimestamp, functionResponseTypes: props.reportBatchItemFailures ? ['ReportBatchItemFailures'] : undefined, maximumBatchingWindowInSeconds: props.maxBatchingWindow?.toSeconds(), maximumRecordAgeInSeconds: props.maxRecordAge?.toSeconds(), @@ -351,4 +366,11 @@ export enum StartingPosition { * always read the most recent data in the shard */ LATEST = 'LATEST', + + /** + * Start reading from a position defined by a time stamp. + * Only supported for Amazon Kinesis streams, otherwise an error will occur. + * If supplied, `startingPositionTimestamp` must also be set. + */ + AT_TIMESTAMP = 'AT_TIMESTAMP', } diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index c1e32caf281b2..05a6ea811ceba 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -1,6 +1,6 @@ import { Match, Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; -import { Code, EventSourceMapping, Function, Runtime, Alias } from '../lib'; +import { Code, EventSourceMapping, Function, Runtime, Alias, StartingPosition } from '../lib'; let stack: cdk.Stack; let fn: Function; @@ -241,4 +241,35 @@ describe('event source mapping', () => { FunctionResponseTypes: Match.absent(), }); }); -}); \ No newline at end of file + + test('AT_TIMESTAMP starting position', () => { + new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + startingPosition: StartingPosition.AT_TIMESTAMP, + startingPositionTimestamp: 1640995200, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', { + StartingPosition: 'AT_TIMESTAMP', + StartingPositionTimestamp: 1640995200, + }); + }); + + test('startingPositionTimestamp missing throws error', () => { + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + startingPosition: StartingPosition.AT_TIMESTAMP, + })).toThrow(/startingPositionTimestamp must be provided when startingPosition is AT_TIMESTAMP/); + }); + + test('startingPositionTimestamp without AT_TIMESTAMP throws error', () => { + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + startingPosition: StartingPosition.LATEST, + startingPositionTimestamp: 1640995200, + })).toThrow(/startingPositionTimestamp can only be used when startingPosition is AT_TIMESTAMP/); + }); +}); From f66f94e9201b9c9d5e0f1b713a6f30194b323b28 Mon Sep 17 00:00:00 2001 From: Julian Michel Date: Thu, 21 Jul 2022 16:53:33 +0200 Subject: [PATCH 3/3] feat(ec2): add R6A instances (#21257) Add support for R6A instances. [Announcement](https://aws.amazon.com/about-aws/whats-new/2022/07/introducing-amazon-ec2-r6a-instances/) Please add tags `pr-linter/exempt-readme` and `pr-linter/exempt-test`. I only added new enum values, therefore no readme changes and test cases should be required. ---- ### All Submissions: * [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-ec2/lib/instance-types.ts | 12 ++++++++++++ packages/@aws-cdk/aws-ec2/test/instance.test.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-ec2/lib/instance-types.ts b/packages/@aws-cdk/aws-ec2/lib/instance-types.ts index ec6e6ebe96926..b303dbdcee201 100644 --- a/packages/@aws-cdk/aws-ec2/lib/instance-types.ts +++ b/packages/@aws-cdk/aws-ec2/lib/instance-types.ts @@ -128,6 +128,16 @@ export enum InstanceClass { */ R5 = 'r5', + /** + * Memory optimized instances based on AMD EPYC, 6th generation + */ + MEMORY6_AMD = 'memory6-amd', + + /** + * Memory optimized instances based on AMD EPYC, 6th generation + */ + R6A = 'r6a', + /** * Memory optimized instances, 6th generation with Intel Xeon Scalable processors (3rd generation processors code named Ice Lake) */ @@ -1046,6 +1056,8 @@ export class InstanceType { [InstanceClass.R4]: 'r4', [InstanceClass.MEMORY5]: 'r5', [InstanceClass.R5]: 'r5', + [InstanceClass.MEMORY6_AMD]: 'r6a', + [InstanceClass.R6A]: 'r6a', [InstanceClass.MEMORY6_INTEL]: 'r6i', [InstanceClass.R6I]: 'r6i', [InstanceClass.MEMORY6_INTEL_NVME_DRIVE]: 'r6id', diff --git a/packages/@aws-cdk/aws-ec2/test/instance.test.ts b/packages/@aws-cdk/aws-ec2/test/instance.test.ts index ffaadfe0cb760..37f0481bbd739 100644 --- a/packages/@aws-cdk/aws-ec2/test/instance.test.ts +++ b/packages/@aws-cdk/aws-ec2/test/instance.test.ts @@ -120,7 +120,7 @@ describe('instance', () => { }); test('instance architecture is correctly discerned for x86-64 instance', () => { // GIVEN - const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i']; // A sample of x86-64 instance classes + const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i', 'r6a']; // A sample of x86-64 instance classes for (const instanceClass of sampleInstanceClasses) { // WHEN