Skip to content
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(stepfunctions-tasks): add support for CodeBuild StartBuild API #9757

Merged
merged 10 commits into from
Aug 21, 2020

Conversation

DaWyz
Copy link
Contributor

@DaWyz DaWyz commented Aug 17, 2020

Implementation

Update package @aws-cdk/aws-stepfunctions-tasks to include support for CodeBuild StartBuild API as per documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/connect-codebuild.html

Includes support for the following Amazon SageMaker API calls:

  • StartBuild

Closes #8043


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @DaWyz - this is a valiant effort and we appreciate the contribution.
at a cursory glance, it feels like we are duplicating some of the modeling in the aws-codebuild module.

I'd suggest taking a step back and scaffolding out support for this service integration.
as a first pass, how about we take a pass without overrides modeled yet.

We will need to support them as well, but to keep this PR moving, it would help substantially to introduce the ability to start a build, by providing an IProject and any other properties that are not representative of overrides.

what do you think?

import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as cdk from '@aws-cdk/core';

import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file feels really large, can we break it down?
would any of this apply for StopBuild - if so we should start moving shared types out.

take a look at the EcsRunTask service integration for inspiration on how to break this down

Comment on lines 555 to 556
'codebuild:BatchGetBuilds',
'codebuild:BatchGetReports',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does StartBuild need these permissions? when would they be used?

Copy link
Contributor Author

@DaWyz DaWyz Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will remove them as I don't think they are useful for the startBuild part.
Do I need codebuild:StopBuild ? I was thinking it might be useful when stopping a Step Function execution but I'm not actually sure stopping the execution would try to stop the codebuild (Haven't tested this part and just started working with Step Functions a couple of weeks ago).

@DaWyz
Copy link
Contributor Author

DaWyz commented Aug 18, 2020

@shivlaks. Thanks for the review.

I was kind of hoping you would say that. I was not really happy with the code of this PR (class too big. It was a pain to implement the _renderTask and I knew it was not a good way to do it).

I like the idea of a smaller PR without having the support for all the override properties. Can I suggest implementing environmentVariablesOverride ? It's a small one and probably one of the most useful (that the only thing I needed for my use case). It would also help me get a guideline on how to implement the rest of the Overrides later on.

What is the best place to get some help if I need to ask for some guidelines on how to implement things (like the bind pattern for the _renderTask. I'm not sure how this works) ?

Only allowing to pass the CodeBuild project and environment variables for now. The rest to come in future iteration.
@mergify mergify bot dismissed shivlaks’s stale review August 20, 2020 00:07

Pull request has been modified.

@DaWyz
Copy link
Contributor Author

DaWyz commented Aug 20, 2020

@shivlaks, I updated the PR and reduced the scope to only passing the CodeBuild Project and environmentVariables.

Could you have a look at it again ?

Also, Am I allowed to use the CfnProject class to reuse interfaces ? Like in the _renderTask method:

codebuild.CfnProject.EnvironmentVariableProperty

@DaWyz DaWyz requested a review from shivlaks August 20, 2020 17:09
Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much cleaner! thanks for simplifying this, it's starting to look pretty close to what i had in mind for a first pass

Comment on lines 5 to 6


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't think these blank lines are needed

* A set of environment variables that overrides, for this build only,
* the latest ones already defined in the build project.
*
* @default No override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @default No override
* @default - No overrides

readonly project: codebuild.IProject;
/**
* A set of environment variables that overrides, for this build only,
* the latest ones already defined in the build project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this describe the default behaviour? maybe it belongs as part of the @default doc string

let startBuild = new tasks.CodeBuildStartBuild(this, 'build-task', {
project: project,
environmentVariablesOverride: {
ZONE: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: any reason why ZONE is all caps? or is it case insensitive when compared to the originally defined environment variables which calls it zone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually set the environment variables in all caps (e.g.: AWS_REGION, NODE_ENV, etc...). Zone is just a random variable name. Happy to change if you think it's confusing.

}

const app = new cdk.App();
new StartBuildStack(app, 'aws-stepfunctions-integ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to give this stack name an id that specifies it's a codebuild integ test

EnvironmentVariablesOverride: this.props.environmentVariablesOverride
? codebuild.Project
.serializeEnvVariables(this.props.environmentVariablesOverride)
.map((environmentVariable: codebuild.CfnProject.EnvironmentVariableProperty) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: your question around codebuild.CfnProject.EnvironmentVariableProperty - since this is not exposed in the public API / surface area that users can interact with, it's acceptable.

I think it's worth asking whether this is the right mechanism to produce the output we want.
What's the alternative? since the function is pretty small, is it maybe better to avoid converting to this Cfn type. Since the module is stable and it's a public static method, I don't think it's an issue since it's not exposed. what do you think?

The thing that makes me wary is that ultimately we're producing ASL and not CloudFormation here so it feels like a roundabout way to get there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I was just trying to reuse the existing serializeEnvVariables from the codebuild.Project class. It's a small method and I can probably go with writing my own and it's going to avoid the round trip.

See the implementation below.

private serializeEnvVariables(environmentVariables: { [name: string]: codebuild.BuildEnvironmentVariable }) {
    return Object.keys(environmentVariables).map(name => ({
      Name: name,
      Type: environmentVariables[name].type || codebuild.BuildEnvironmentVariableType.PLAINTEXT,
      Value: environmentVariables[name].value,
    }));
  }

@mergify mergify bot dismissed shivlaks’s stale review August 21, 2020 02:07

Pull request has been modified.

@DaWyz DaWyz requested a review from shivlaks August 21, 2020 02:54
Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome turnaround on this! we really appreciate the contribution!!! 🎉

@mergify
Copy link
Contributor

mergify bot commented Aug 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: ebdbdbd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Aug 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit dae54ec into aws:master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Step Functions service integration for CodeBuild tasks
3 participants