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

[Bug]: adf-account-management StateMachine fails if first 30 characters of account name are similar. #770

Open
1 of 2 tasks
niklaswesterstrahleknowit opened this issue Oct 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@niklaswesterstrahleknowit

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When you create multiple accounts in a single file the StateMachine fails to start cause stepfunctions states that it has already been started:

[ERROR] ExecutionAlreadyExists: An error occurred (ExecutionAlreadyExists) when calling the StartExecution operation: Execution Already Exists: 'arn:aws:states:us-east-1:xxxxxxxxxxx:execution:adf-account-management:LongClientName___Business_Names__-29a4174a-4ce7-4597-bc58-89fda1121172-96ac41b3da60'
Traceback (most recent call last):
File "/var/task/process_account_files.py", line 206, in lambda_handler
start_executions(
File "/var/task/process_account_files.py", line 179, in start_executions
sfn_client.start_execution(
File "/var/task/botocore/client.py", line 565, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/task/aws_xray_sdk/ext/botocore/patch.py", line 38, in _xray_traced_botocore
return xray_recorder.record_subsegment(
File "/var/task/aws_xray_sdk/core/recorder.py", line 456, in record_subsegment
return_value = wrapped(*args, **kwargs)
File "/var/task/botocore/client.py", line 1021, in _make_api_call
raise error_class(parsed_response, operation_name)

So in case the accounts follow a naming standard like:
LongClientName - BusinessName - Development/Production etc

The 30 selected first letters + id from process_account_files.py sends the exact same ID for both accounts into step functions.

Expected Behavior

Should run for each account in the account file, with zero regard to the naming being similar.

Current Behavior

ERROR] ExecutionAlreadyExists: An error occurred (ExecutionAlreadyExists) when calling the StartExecution operation: Execution Already Exists: 'arn:aws:states:us-east-1:xxxxxxxxxxx:execution:adf-account-management:LongClientName___Business_Names__-29a4174a-4ce7-4597-bc58-89fda1121172-96ac41b3da60'

The execution of the file stops - it will not try to run the state machines for accounts below the first failure either.

Steps To Reproduce

Add two new accounts into the account file, with first characters being the same.

Possible Solution

Add a short random string in front of the account name, instead of behind in step function trigger.

Additional Information/Context

No response

ADF Version

4.0.0

Contributing a fix?

  • Yes, I am working on a fix to resolve this issue
@niklaswesterstrahleknowit niklaswesterstrahleknowit added the bug Something isn't working label Oct 14, 2024
@niklaswesterstrahleknowit
Copy link
Author

My suggestion as a not really coding individual, would be to take chatgpt's help on this:

import re
import random
import string

def sanitize_account_name_for_snf(account_name):
sanitized_name = re.sub(r"[^a-zA-Z0-9_]", "", account_name[:26])
random_string = ''.join(random.choices(string.ascii_lowercase + string.digits, k=3))
return f"{sanitized_name}
{random_string}"

@niklaswesterstrahleknowit
Copy link
Author

I ended up testing this:

`Date: Tue Oct 29 08:55:13 2024 +0000

Adding a random string to sanitized account name used for step function execution

diff --git a/src/lambda_codebase/account_processing/process_account_files.py b/src/lambda_codebase/account_processing/process_account_files.py
index 32996fc..35687ad 100644
--- a/src/lambda_codebase/account_processing/process_account_files.py
+++ b/src/lambda_codebase/account_processing/process_account_files.py
@@ -13,6 +13,7 @@ import tempfile
import logging
from typing import Any, TypedDict
import re
+import random

import yaml
from yaml.error import YAMLError
@@ -144,7 +145,10 @@ def process_account_list(all_accounts, accounts_in_file):

def sanitize_account_name_for_snf(account_name):

  • return re.sub(r"[^a-zA-Z0-9_]", "_", account_name[:30])
  • sanitized_name = re.sub(r"[^a-zA-Z0-9_]", "_", account_name[:26])
  • allowed_characters = "abcdefghijklmnopqrstuvwxyz0123456789"
  • random_string = ''.join(random.choices(allowed_characters, k=3))
  • return f"{sanitized_name}_{random_string}"
    `

And can confirm that this works..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant