-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(scheduler-targets-alpha): KinesisStreamPutRecord
Target
#27845
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
This reverts commit 40d4e14.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, thanks 👍
The unit tests on imported streams will require a fix on the importing function.
/** | ||
* The shard to which EventBridge Scheduler sends the event. | ||
* | ||
* A length of `partitionKey` must be between 1 and 256. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* A length of `partitionKey` must be between 1 and 256. | |
* The length must be between 1 and 256. |
test('throws when stream is imported from different account', () => { | ||
const stack2 = new Stack(app, 'Stack2', { | ||
env: { | ||
region: 'us-east-1', | ||
account: '234567890123', | ||
}, | ||
}); | ||
|
||
const importedStream = kinesis.Stream.fromStreamArn(stack2, 'ImportedStream', 'arn:aws:kinesis:us-east-1:234567890123:stream/Foo'); | ||
const streamTarget = new KinesisStreamPutRecord(importedStream, { | ||
partitionKey: 'key', | ||
}); | ||
|
||
expect(() => | ||
new Schedule(stack, 'MyScheduleDummy', { | ||
schedule: expr, | ||
target: streamTarget, | ||
})).toThrow(/Both the schedule and the stream must be in the same account/); | ||
}); | ||
|
||
test('throws when stream is imported from different region', () => { | ||
const stack2 = new Stack(app, 'Stack2', { | ||
env: { | ||
region: 'us-west-2', | ||
account: '123456789012', | ||
}, | ||
}); | ||
|
||
const importedStream = kinesis.Stream.fromStreamArn(stack2, 'ImportedStream', 'arn:aws:kinesis:us-west-2:123456789012:stream/Foo'); | ||
const streamTarget = new KinesisStreamPutRecord(importedStream, { | ||
partitionKey: 'key', | ||
}); | ||
|
||
expect(() => | ||
new Schedule(stack, 'MyScheduleDummy', { | ||
schedule: expr, | ||
target: streamTarget, | ||
})).toThrow(/Both the schedule and the stream must be in the same region/); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('throws when stream is imported from different account', () => { | |
const stack2 = new Stack(app, 'Stack2', { | |
env: { | |
region: 'us-east-1', | |
account: '234567890123', | |
}, | |
}); | |
const importedStream = kinesis.Stream.fromStreamArn(stack2, 'ImportedStream', 'arn:aws:kinesis:us-east-1:234567890123:stream/Foo'); | |
const streamTarget = new KinesisStreamPutRecord(importedStream, { | |
partitionKey: 'key', | |
}); | |
expect(() => | |
new Schedule(stack, 'MyScheduleDummy', { | |
schedule: expr, | |
target: streamTarget, | |
})).toThrow(/Both the schedule and the stream must be in the same account/); | |
}); | |
test('throws when stream is imported from different region', () => { | |
const stack2 = new Stack(app, 'Stack2', { | |
env: { | |
region: 'us-west-2', | |
account: '123456789012', | |
}, | |
}); | |
const importedStream = kinesis.Stream.fromStreamArn(stack2, 'ImportedStream', 'arn:aws:kinesis:us-west-2:123456789012:stream/Foo'); | |
const streamTarget = new KinesisStreamPutRecord(importedStream, { | |
partitionKey: 'key', | |
}); | |
expect(() => | |
new Schedule(stack, 'MyScheduleDummy', { | |
schedule: expr, | |
target: streamTarget, | |
})).toThrow(/Both the schedule and the stream must be in the same region/); | |
}); | |
test.each([ | |
['account', 'arn:aws: kinesis:us-east-1:999999999999:stream/Foo', /Both the schedule and the stream must be in the same account./], | |
['region', 'arn:aws: kinesis:eu-central-1:123456789012:stream/Foo', /Both the schedule and the stream must be in the same region./], | |
])('throws when Kinesis Data Stream is imported from different %s', (_, arn: string, expectedError: RegExp) => { | |
const importedStream = kinesis.Stream.fromStreamArn(stack, 'ImportedStream', arn); | |
const streamTarget = new KinesisStreamPutRecord(importedStream, { | |
partitionKey: 'key', | |
}); | |
expect(() => | |
new Schedule(stack, 'MyScheduleDummy', { | |
schedule: expr, | |
target: target, | |
})).toThrow(expectedError); | |
}); |
fromStreamArn
should use the same stack.
fromStreamAttributes
will require to solve the environment for the imported stream ARN:
public static fromStreamAttributes(scope: Construct, id: string, attrs: StreamAttributes): IStream {
class Import extends StreamBase {
public readonly streamArn = attrs.streamArn;
public readonly streamName = Stack.of(scope).splitArn(attrs.streamArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!;
public readonly encryptionKey = attrs.encryptionKey;
}
return new Import(scope, id, {
environmentFromArn: attrs.streamArn,
});
}
Also, can you please add unit tests to verify that the environment gets resolved correctly when using fromStreamArn
and fromStreamAttributes
after this change?
I just changed! Please check them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
KinesisStreamPutRecord
Target
Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @go-to-k , thank you for this contribution.
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Pull request has been modified.
Thanks for your approval! I fixed conflicts. Please approve again. I fixed the other PR the same way, but when one of them gets merged, the other one gets conflicts again. If that happens, I will fix it again. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR adds KinesisStreamPutRecord Target for EventBridge Scheduler.
Closes #27451.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license