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: Added support for random sleep delay in deploy submodule #233

Merged
merged 5 commits into from
Nov 22, 2021

Conversation

pkleanthous
Copy link
Contributor

Description

Adding here 2 minor tweaks to the deploy sub-module that I found useful.

Motivation and Context

  1. When I deploy multiple lambdas and use the wait_deployment_completion the AWS is throttling the CLI calls and the script fails. Here, I'm introducing the get_deployment_sleep_timer variable that it can increase the sleep time. Also the sleep time is a random number between (0 and 10) + ${get_deployment_sleep_timer}.

  2. I want to separate the infrastructure deployment from the lambda lambda function release via CodeDeploy. The motivation behind this is to capture any issues that introduced by the infrastructure changes.
    An example is, you change the permissions for a resource that a lambda function use, the old version immediately louses access and you wait until the traffic switches to the new version that has all the right permissions. So the run_deployment now will trigger the bash script otherwise deploy the infra, save the script and run it whenever you want.

Breaking Changes

In order to run the deployment bash script now you need to set run_deployment = true

How Has This Been Tested?

  • Both features are tested in a private project. Please let me know that evidence I should provide here.

modules/deploy/main.tf Outdated Show resolved Hide resolved

SLEEP_TIME=$(( $RANDOM % 10 ) + ${var.get_deployment_sleep_timer})
echo "Sleeping for: $SLEEP_TIME Seconds"
sleep $SLEEP_TIME
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that aws deploy get-deployment is being throttled? Sounds strange because it is a read type of operation even if it is executed multiple times at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @antonbabenko,

Thanks for your review.

In a busy day when we make multiple AWS API calls we get something like:
An error occurred (ThrottlingException) when calling the GetDeployment operation (reached max retries: 4): Rate exceeded

I think the following link describes the error (even if it's a few years old): https://forums.aws.amazon.com/thread.jspa?messageID=892511

Copy link
Member

Choose a reason for hiding this comment

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

Right. Let's drop the get_deployment_sleep_timer variable because it is not necessary, but just sleep for 5 to 10 seconds, like this:

SLEEP_TIME=$(( $RANDOM % 5 ) + 5)

Short and simpler.

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 prefer to parameterize the sleep timer, as even if you are shifting 50% of the traffic every minute, you don't need to check the progress every ~ 5 seconds.

Is it a deal breaker for you if we keep the get_deployment_sleep_timer and set the default to 5?

Copy link
Member

Choose a reason for hiding this comment

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

It is not a deal-breaker for me but I was not familiar with the use-case you had, so trying to balance between code simplicity and required flexibility. Let's keep it as you proposed. :)

@@ -106,7 +109,7 @@ resource "local_file" "deploy_script" {
}

resource "null_resource" "deploy" {
count = var.create && var.create_deployment ? 1 : 0
count = var.create && var.create_deployment && var.run_deployment ? 1 : 0
Copy link
Member

Choose a reason for hiding this comment

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

Looks good. Could you also update related examples in the examples/deploy directory and verify them?


SLEEP_TIME=$(( $RANDOM % 10 ) + ${var.get_deployment_sleep_timer})
echo "Sleeping for: $SLEEP_TIME Seconds"
sleep $SLEEP_TIME
Copy link
Member

Choose a reason for hiding this comment

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

Right. Let's drop the get_deployment_sleep_timer variable because it is not necessary, but just sleep for 5 to 10 seconds, like this:

SLEEP_TIME=$(( $RANDOM % 5 ) + 5)

Short and simpler.

@antonbabenko antonbabenko changed the title chore: minor improvements feat: Added support for random sleep delay in deploy submodule Nov 18, 2021
Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

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

Please revert the version requirements since the change introduced in this PR does not require them, and update the docs. It is almost done.

examples/deploy/versions.tf Outdated Show resolved Hide resolved
examples/deploy/versions.tf Outdated Show resolved Hide resolved
@antonbabenko antonbabenko merged commit 65f3717 into terraform-aws-modules:master Nov 22, 2021
@antonbabenko
Copy link
Member

Thanks, @pkleanthous !

v2.27.0 has been just released.

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants