aws-lambda Added CodeBuild CloudWatch state event#45490
aws-lambda Added CodeBuild CloudWatch state event#45490elibarzilay merged 10 commits intoDefinitelyTyped:masterfrom
Conversation
|
@ivanmartos Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — keep an eye on this comment as I'll be updating it with information as things progress. Code ReviewsBecause this PR edits the configuration file, it can be merged once it's reviewed by a DT maintainer. Status
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 45490,
"author": "ivanmartos",
"owners": [
"darbio",
"skarum",
"StefH",
"tobyhede",
"buggy",
"y13i",
"wwwy3y3",
"OrthoDex",
"MichaelMarner",
"daniel-cottone",
"kostya-misura",
"coderbyheart",
"palmithor",
"daniloraisi",
"simonbuchan",
"Haydabase",
"repl-chris",
"aneilbaboo",
"jeznag",
"louislarry",
"dpapukchiev",
"ohookins",
"trevor-leach",
"jagregory",
"dalen",
"loikg",
"skyzenr",
"redlickigrzegorz",
"juancarbonel",
"pwmcintyre",
"alex-bolenok-centralreach",
"marianzange",
"apepper",
"apalumbo",
"SachinShekhar"
],
"dangerLevel": "ScopedAndConfiguration",
"headCommitAbbrOid": "7cbc1f3",
"headCommitOid": "7cbc1f3b3cf2f0087f9e7b78b0df90d4083715a1",
"mergeIsRequested": false,
"stalenessInDays": 6,
"lastCommitDate": "2020-06-17T08:45:35.000Z",
"lastCommentDate": "2020-06-17T07:33:12.000Z",
"reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45490/files",
"hasMergeConflict": false,
"authorIsOwner": false,
"isFirstContribution": true,
"popularityLevel": "Popular",
"anyPackageIsNew": false,
"packages": [
"aws-lambda"
],
"files": [
{
"filePath": "types/aws-lambda/aws-lambda-tests.ts",
"kind": "test",
"package": "aws-lambda"
},
{
"filePath": "types/aws-lambda/index.d.ts",
"kind": "definition",
"package": "aws-lambda"
},
{
"filePath": "types/aws-lambda/test/codebuild-tests.ts",
"kind": "test",
"package": "aws-lambda"
},
{
"filePath": "types/aws-lambda/trigger/codebuild-cloudwatch-state.d.ts",
"kind": "definition",
"package": "aws-lambda"
},
{
"filePath": "types/aws-lambda/tsconfig.json",
"kind": "package-meta",
"package": "aws-lambda"
}
],
"hasDismissedReview": false,
"ciResult": "pass",
"lastReviewDate": "2020-06-17T09:00:48.000Z",
"reviewersWithStaleReviews": [],
"approvalFlags": 2,
"isChangesRequested": false
} |
|
🔔 @darbio @skarum @StefH @tobyhede @buggy @y13i @wwwy3y3 @OrthoDex @MichaelMarner @daniel-cottone @kostya-misura @coderbyheart @palmithor @daniloraisi @simonbuchan @Haydabase @repl-chris @aneilbaboo @jeznag @louislarry @dpapukchiev @ohookins @trevor-leach @jagregory @dalen @loikg @skyzenr @redlickigrzegorz @juancarbonel @pwmcintyre @alex-bolenok-centralreach @marianzange @apepper @apalumbo @SachinShekhar - please review this PR in the next few days. Be sure to explicitly select |
|
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
simonbuchan
left a comment
There was a problem hiding this comment.
Thanks for all this work! A few notes and quibbles, but this looks fine to merge overall to me.
| | 'BUILD_GENERAL1_2XLARGE'; | ||
| export type CodeBuildEnvironmentVariableType = 'PARAMETER_STORE' | 'PLAINTEXT'; | ||
|
|
||
| export interface CodeBuildCloudWatchStateEvent { |
There was a problem hiding this comment.
This should be able to use the CloudWatchEvent<> (?) template, passing in the detail type and detail.
There was a problem hiding this comment.
not sure what you mean here. Could you please explain a bit more? I based this PR on the codepipeline-cloudwatch* types. Can't seem to find if there
There was a problem hiding this comment.
Sorry, was me being on a phone again. I was referring to the EventBridgeEvent<TDetailType extends string, TDetail> in trigger/eventbridge.d.ts which seems to be what this structure is based on. It's more for users to be able to compose their own custom event structures though.
| /* CodeBuild CloudWatch Events | ||
| * see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html | ||
| */ | ||
| const CodeBuildCloudWatchStateEvent: CodeBuildCloudWatchStateEvent = { |
There was a problem hiding this comment.
Ideally tests should be using the handler types, like a user would, but we still have several in this style. It's much less important when there isn't a result type though.
There was a problem hiding this comment.
after I gave it a bit of thought it makes more sense to remove those Codebuild specific handlers. In my project I'm currently receiving these types as a message of SNSEvent triggered by CloudWatch event. That means that if I needed to create a handler, I would be just replicating SNS types
I already removed those handlers
Thanks
There was a problem hiding this comment.
Sorry, wrote the first review on a phone, so I was a bit terse. I'm referring to writing the test that uses the types as a user would use the types, e.g. writing a handler that reads the fields. This catches a lot of broken changes or unexpected warts in using types.
So for this package that would be writing a handler type, normally something like:
const someHandler: SomeHandler = async (event) => {
strOrUndefined = event.someOptionalField;
...
};though it's a bit more complicated with a result type.
There was a problem hiding this comment.
I understand what you mean about the test of handler. What I wanted to say is that handler does not directly receive CodeBuildCloudWatchStateEvent, but it receives SNSEvent with record that contains CodeBuildCloudWatchStateEvent as a JSON string in Message
Something like
import { CodeBuildCloudWatchStateEvent, SNSEvent } from 'aws-lambda'
export const handleCodebuildEvent = async (event: SNSEvent) => {
const record = event.Records[0]
const codebuildEvent: CodeBuildCloudWatchStateEvent = JSON.parse(record.Sns.Message)
}
I haven't tried integration with EventBridge, only via CloudWatch Event and SNS.
Basically the use case is that you have CloudWatch event defined that checks CodeBuild state changes. Upon event it pushes a message to SNS topic and there is lambda subscribed to this SNS topic. This lambda consumes the messages as in a code of block above.
I already have working monitoring of CodePipelines in the same way - CloudWatch event checks CodePipeline executions and upon event it pushes messages to SNS topic and there is lambda subscribed to that topic
import { CodePipelineCloudWatchActionEvent, SNSEvent } from 'aws-lambda'
export const handlePipelineEvent = async (event: SNSEvent) => {
const record = event.Records[0]
const pipelineEvent: CodePipelineCloudWatchActionEvent = JSON.parse(record.Sns.Message)
}
In this use case I'm not sure it makes sense to create a test for handler, cause I would be testing the SNSEvent in the handler, not the CodeBuildCloudWatchStateEvent - since handler receives type of SNSEvent and the CodeBuildCloudWatchStateEvent is just a stringified JSON in the SNSEvent
However if you feel strong about it I can add the test that will contain SNSEvent as an event type of handler and it will contain JSON string of CodeBuildCloudWatchStateEvent and in the end I will just check whether the Message of SNSEvent consists the same stringified JSON
There was a problem hiding this comment.
EventBridge is just CloudWatch Events renamed. Presumably you can just send these events straight to lambda: (I haven't messed with anything other than scheduled events), this would be the handler type.
I would somewhat strongly prefer that the test was reading from the event, not creating one, as that catches problems with changes to the structure.
With SNS usage as the test, this might look something like:
export const handlePipelineEvent = async (snsEvent: SNSEvent) => {
const event: CodePipelineCloudWatchActionEvent = JSON.parse(snsEvent.Records[0].Sns.Message)
str = event.version;
str = event.id;
// and so on for the rest of the fields, using types from `aws-lambda-tests.ts` where appropriate.
}but obviously, that's quite a decent bit of work, so I'm not going to block on that, much better to have this merged.
There was a problem hiding this comment.
For comparison, here's an example of a test parsing data from the event to get further data:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/test/cloudwatch-tests.ts#L13-L15
Note that unless you're getting this as an event directly in a handler, this type shouldn't have the ...Event suffix, maybe something like ...MessageData? But I think you can and thus should use the EventBridge handler structure.
There was a problem hiding this comment.
ok, no problem
I'll modify it and add the tests 👍
| | 'BUILD_GENERAL1_MEDIUM' | ||
| | 'BUILD_GENERAL1_LARGE' | ||
| | 'BUILD_GENERAL1_2XLARGE'; | ||
| export type CodeBuildEnvironmentVariableType = 'PARAMETER_STORE' | 'PLAINTEXT'; |
There was a problem hiding this comment.
I'm not a big fan of calling types "types", but really it's more important to be consistent with the property name, documentation and the rest of the package, in that order, and it's not really that important.
There was a problem hiding this comment.
I based the naming on the sdk documentation and there they explicitly use type
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeBuild.html
|
@simonbuchan Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
simonbuchan
left a comment
There was a problem hiding this comment.
I'm going to put this on hold for a second, as I'm a bit confused about the handler type being removed.
According to my understanding of the CodeBuild notification docs, these structures are what are delivered to SNS, not to Lambda, and this would only be the structure if the SNS template is a passthrough. But other documentation refers to the event being delivered to EventBridge:
In Detail type, choose Basic if you want only the information provided to Amazon EventBridge included in the notification.
But I can't seem to find the documentation for the actual EventBridge stuff that lambda could receive, which is what this package generally is focused on, structures defined by AWS, and for lambda triggers, not just structures that you could happen to use in lambda. I think there are a few examples of structures that are delivered as JSON in an event, but they're pretty rare.
Just to reiterate, this isn't a no: just a check that this does actually make sense for this to be added in this package.
| /* CodeBuild CloudWatch Events | ||
| * see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html | ||
| */ | ||
| const CodeBuildCloudWatchStateEvent: CodeBuildCloudWatchStateEvent = { |
There was a problem hiding this comment.
Sorry, wrote the first review on a phone, so I was a bit terse. I'm referring to writing the test that uses the types as a user would use the types, e.g. writing a handler that reads the fields. This catches a lot of broken changes or unexpected warts in using types.
So for this package that would be writing a handler type, normally something like:
const someHandler: SomeHandler = async (event) => {
strOrUndefined = event.someOptionalField;
...
};though it's a bit more complicated with a result type.
| | 'BUILD_GENERAL1_2XLARGE'; | ||
| export type CodeBuildEnvironmentVariableType = 'PARAMETER_STORE' | 'PLAINTEXT'; | ||
|
|
||
| export interface CodeBuildCloudWatchStateEvent { |
There was a problem hiding this comment.
Sorry, was me being on a phone again. I was referring to the EventBridgeEvent<TDetailType extends string, TDetail> in trigger/eventbridge.d.ts which seems to be what this structure is based on. It's more for users to be able to compose their own custom event structures though.
|
@ivanmartos One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. If you disagree with the reviewer's comments, you can "dismiss" the review using GitHub's review UI. Thank you! |
simonbuchan
left a comment
There was a problem hiding this comment.
That was fast! Thanks for putting up with me through this!
|
Updated numbers for you here from 7ab9466. Comparison details 📊
Looks like there were a couple significant differences—take a look at worst-case duration for getting completions at a position to make sure everything looks ok. |
|
I just published |
) * added type and handler for CodeBuild Cloudwatch State event * added type and handler for CodeBuild Cloudwatch event * added test for codebuild cloudwatch event * extended definitions block * added SECRETS_MANAGER as environment variable type * removed handlers * removed unnecessary general codebuild types * CodeBuildCloudWatchStateEvent extends EventBridgeEvent and added CodeBuildCloudWatchStateHandler * added general type strArrayOrUndefined for tests * added tests for CodeBuildCloudWatchStateHandler
Please fill in this template.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }. If for reason the any rule need to be disabled, disable it for that line using// tslint:disable-next-line [ruleName]and not for whole package so that the need for disabling can be reviewed.Related https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html