-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
AWS Synthetics Canary Missing support for Environment Variables #17948
Comments
Synthetics Canary environment variable support was made available in AWS SDK v1.35.29 but has not yet been implemented in the |
I am also looking for support to use ENV variables but its not currently not supported. I will raise a PR soon with relevant changes. |
Impact of this not being enabled: I'm also looking to deploy canaries in bulk via for_each. This isue is blocking that since I can't assign url/strings to check with environmental variables and canaries don't allow feeding inputs with events like Lambda allows. |
We are also facing this issue. We wish to use a common script for running tests on all of our environments (e.g. dev/test/prod), but use an environment variable for the URL to access, and are unable to define this in our terraform scripts. |
I looked into this issue and found |
I am also looking for support to use ENV variables but its not currently not supported. |
My code is very similar and it fails with this error ERROR: Canary error: |
I neglected to read this comment and started to see if I could add this feature here, but then also discovered it is not possible to read the current environment variables from a canary, resulting in I think this issue is not related to the aws-sdk-go, but the service's API itself. I opened aws/aws-sdk-go#3982. Hopefully environment variables will be added in the future 😄 . |
I am also looking for support to use ENV variables but its not currently not supported. |
One way to grab the environment variables would be to grab the An example using the CLI and jq: export ENGINE_ARN=$(aws synthetics get-canary --name=<canary_name> | jq '.Canary.EngineArn' | xargs)
aws lambda get-function-configuration --function-name=$ENGINE_ARN | jq '.Environment.Variables' Could this be a reasonable approach for the Terraform AWS provider? I'd love to see this feature in the Synthetics Canary resource too |
Dear fellow nerds, Given that the AWS API doesn't even support displaying the environment variables for a canary, it will probably take a long time to even be able to support this without a lot of hoop-jumping (e.g. querying the lambda API to get the current environment variables for the function the canary is tied to). I put together the following code in my module to support setting environment variables at create time and whenever any of the A few caveats:
Without further ado, here's how I'm doing this: locals {
canary_name = "foo"
canary_timeout_in_seconds = 30
canary_memory_limit_in_mb = 960
canary_active_tracing_enabled = false
canary_environment_variables = { FOO: "BAR" }
set_canary_run_config_command = "aws synthetics update-canary --name ${local.canary_name} --run-config '${jsonencode({TimeoutInSeconds: local.canary_timeout_in_seconds, MemoryInMB: local.canary_memory_limit_in_mb, ActiveTracing: local.canary_active_tracing_enabled, EnvironmentVariables: local.canary_environment_variables })}'"
}
resource "aws_synthetics_canary" "healthchecks" {
name = local.canary_name
start_canary = true
s3_bucket = aws_s3_bucket_object.canary_script.bucket
s3_key = aws_s3_bucket_object.canary_script.key
artifact_s3_location = "s3://${aws_s3_bucket.canary_bucket.id}/"
execution_role_arn = aws_iam_role.canary.arn
handler = "apiCanaryBlueprint.handler"
runtime_version = "syn-nodejs-puppeteer-3.3"
schedule {
expression = "rate(1 hour)"
}
run_config {
active_tracing = local.canary_active_tracing_enabled
memory_in_mb = local.canary_memory_limit_in_mb
timeout_in_seconds = local.canary_timeout_in_seconds
}
}
resource "null_resource" "add_environment_variables_to_canary" {
# Run this command again whenever any of the run-config parameters change
triggers = {
canary_active_tracing_enabled = local.canary_active_tracing_enabled
canary_memory_limit_in_mb = local.canary_memory_limit_in_mb
canary_timeout_in_seconds = local.canary_timeout_in_seconds
# Trigger values must be strings (or implicitly coerced into strings, like bools), so turn env vars into a string like FOO=bar,FIZZ=buzz
canary_environment_variables = join(",", [ for key, value in local.canary_environment_variables: "${key}=${value}" ])
}
provisioner "local-exec" {
command = local.set_canary_run_config_command
}
depends_on = [ aws_synthetics_canary.healthchecks ]
}
|
This functionality has been released in v4.5.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Description
At present, it would appear the AWS Provider does not yet support the ability to set environment variables for
aws_synthetics_canary
resources. As they share some similarities, I was expecting canary resources to support environment variables in a much similar fashion to Lambda Functions.It would appear that in the original PR to add canary support, there was a attempt to bring in support for environment variables which was subsequently reverted, presumably due to some kind of bug or limitation somewhere. If this was indeed the case, then it would be nice to have this feature included again whenever possible.
New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: