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(synthetics): support canary environment variables #15082

Merged
merged 11 commits into from
Jun 16, 2021

Conversation

BenChaimberg
Copy link
Contributor

@BenChaimberg BenChaimberg commented Jun 11, 2021

Add support for canary environment variables that will be threaded to the underlying Lambda function. This allows multiple canaries to use the same source code by extracting configuration to the resource specification.

Also makes the README snippets compile since it was hard to tell whether my changes were correct.

closes #10515
refer #9300

Co-authored-by: Florian Chazal florianchazal@gmail.com


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

@gitpod-io
Copy link

gitpod-io bot commented Jun 11, 2021

@BenChaimberg BenChaimberg requested review from NetaNir and a team June 11, 2021 04:35
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 11, 2021
@BenChaimberg BenChaimberg added @aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics p1 labels Jun 11, 2021
@BenChaimberg BenChaimberg self-assigned this Jun 11, 2021
@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Jun 11, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Good stuff! Only minor comments below.
You can decide if they're worth it or not.

packages/@aws-cdk/aws-synthetics/README.md Outdated Show resolved Hide resolved
*
* @default - No environment variables.
*/
readonly environmentVariables?: { [key: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: Just environment is sufficient.

In some of our target languages, it can get even longer (eg: withEnvironmentVariables()). Would be nice to be terse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NetaNir mentioned she wanted something more explicit – thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

We call it environment in Lambda - https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html#environment. No one has complained so far.

Copy link
Contributor

Choose a reason for hiding this comment

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

The context in Lambda is clear, it's the function environment variables, in the synthetics module there is not definition of a function, the user only pass a Code type, so environment does not have any context.

packages/@aws-cdk/aws-synthetics/test/canary.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-synthetics/README.md Outdated Show resolved Hide resolved
@@ -306,6 +314,7 @@ export class Canary extends cdk.Resource {
failureRetentionPeriod: props.failureRetentionPeriod?.toDays(),
successRetentionPeriod: props.successRetentionPeriod?.toDays(),
code: this.createCode(props),
runConfig: this.createRunConfig(props),
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
runConfig: this.createRunConfig(props),
runConfig: props.environmentVariables ?? {
environmentVariables: props.environmentVariables,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you suggesting that I ditch the createRunConfig function? or that the run config shouldn't exist if env vars aren't supplied (as this is already the case)

@BenChaimberg BenChaimberg removed the pr/do-not-merge This PR should not be merged at this time. label Jun 16, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 16, 2021

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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: b1db2fe
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit df9f13f into master Jun 16, 2021
@mergify mergify bot deleted the chaimber/synthetics_envvar branch June 16, 2021 23:53
@mergify
Copy link
Contributor

mergify bot commented Jun 16, 2021

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).

matthewsvu pushed a commit to matthewsvu/aws-cdk that referenced this pull request Jun 22, 2021
Add support for canary environment variables that will be threaded to the underlying Lambda function. This allows multiple canaries to use the same source code by extracting configuration to the resource specification.

Also makes the README snippets compile since it was hard to tell whether my changes were correct.

closes aws#10515
refer aws#9300

Co-authored-by: Florian Chazal <florianchazal@gmail.com>

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
Add support for canary environment variables that will be threaded to the underlying Lambda function. This allows multiple canaries to use the same source code by extracting configuration to the resource specification.

Also makes the README snippets compile since it was hard to tell whether my changes were correct.

closes aws#10515
refer aws#9300

Co-authored-by: Florian Chazal <florianchazal@gmail.com>

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics contribution/core This is a PR that came from AWS. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[synthetics] Support setting environment variables during canary creation
4 participants