Skip to content

Commit

Permalink
Revert "Merge pull request #480 from troy-ameigh/main"
Browse files Browse the repository at this point in the history
This reverts commit d7e1624, reversing
changes made to ccfccfd.

Revert "Merge pull request #479 from troy-ameigh/main"

This reverts commit ccfccfd, reversing
changes made to 4aec0da.
  • Loading branch information
hanafya committed Jul 31, 2024
1 parent d7e1624 commit 5303565
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
22 changes: 9 additions & 13 deletions sources/aft-lambda-layer/aft_common/aft_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ def wrapper(*args: Optional[Tuple[Any]], **kwargs: Optional[Dict[str, Any]]) ->
except ClientError as e:
if e.response["Error"]["Code"] in BOTO3_CLIENT_ERROR_THROTTLING_CODES:
if requests >= max_requests:
if requests.isalnum():
logger.info(
f"Exceeded max fresh-request retry attempts ({max_requests})"
)
raise e
if retry_sleep_sec.isalnum():
logger.info(
f"Exceeded max boto3 retries on previous request. Retrying with fresh request in {retry_sleep_sec} seconds."
f"Exceeded max fresh-request retry attempts ({max_requests})"
)
raise e

logger.info(
f"Exceeded max boto3 retries on previous request. Retrying with fresh request in {retry_sleep_sec} seconds."
)
requests += 1
time.sleep(retry_sleep_sec)

Expand Down Expand Up @@ -125,16 +124,14 @@ def invoke_lambda(
payload: Union[bytes, IO[bytes], StreamingBody],
) -> InvocationResponseTypeDef:
client: LambdaClient = session.client("lambda")
if function_name.isalnum():
logger.info(f"Invoking Lambda: {function_name}")
logger.info(f"Invoking Lambda: {function_name}")
response = client.invoke(
FunctionName=function_name,
InvocationType="Event",
LogType="Tail",
Payload=payload,
)
if response.isalnum():
logger.info(response)
logger.info(response)
return response


Expand All @@ -156,8 +153,7 @@ def invoke_step_function(
) -> StartExecutionOutputTypeDef:
client: SFNClient = session.client("stepfunctions")
sfn_arn = build_sfn_arn(session, sfn_name)
if sfn_arn.isalnum():
logger.info("Starting SFN execution of " + sfn_arn)
logger.info("Starting SFN execution of " + sfn_arn)
response = client.start_execution(stateMachineArn=sfn_arn, input=input)
logger.debug(response)
return response
Expand Down
4 changes: 2 additions & 2 deletions sources/aft-lambda-layer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[build-system]
requires = [
"setuptools == 70.0.0",
"setuptools",
"wheel",
]

Expand All @@ -26,7 +26,7 @@ classifiers=[
dependencies = [
"boto3 == 1.28.17",
"botocore == 1.31.17",
"requests == 2.32.2",
"requests == 2.31.0",
"jsonschema == 4.3.2",
]

Expand Down
19 changes: 8 additions & 11 deletions src/aft_lambda/aft_builder/codebuild_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def lambda_handler(event: Dict[str, Any], context: Dict[str, Any]) -> LayerBuild
codebuild_project_name = event["codebuild_project_name"]
job_id = client.start_build(projectName=codebuild_project_name)["build"]["id"]

if codebuild_project_name.isalnum():
logger.info(f"Started build project {codebuild_project_name} job {job_id}")
logger.info(f"Started build project {codebuild_project_name} job {job_id}")

# Wait at least 30 seconds for the build to initialize
time.sleep(30)
Expand All @@ -44,16 +43,14 @@ def lambda_handler(event: Dict[str, Any], context: Dict[str, Any]) -> LayerBuild
time.sleep(10)
continue
elif job_status == "SUCCEEDED":
if job_id.isalnum():
logger.info(f"Build job {job_id} completed successfully")
return {"Status": 200}
logger.info(f"Build job {job_id} completed successfully")
return {"Status": 200}
else:
if job_id.isalnum():
logger.info(f"Build {job_id} failed - non-success terminal status")
raise Exception(f"Build {job_id} failed - non-success terminal status")
if job_id.isalnum():
logger.info(f"Build {job_id} failed - time out")
raise Exception(f"Build {job_id} failed - time out")
logger.info(f"Build {job_id} failed - non-success terminal status")
raise Exception(f"Build {job_id} failed - non-success terminal status")

logger.info(f"Build {job_id} failed - time out")
raise Exception(f"Build {job_id} failed - time out")

except Exception as error:
message = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, A
running_pipelines = int(event["running_executions"]["running_pipelines"])
pipelines_to_run = maximum_concurrent_pipelines - running_pipelines
accounts = event["targets"]["pending_accounts"]
if accounts.isalnum():
logger.info("Accounts submitted for execution: " + str(len(accounts)))
logger.info("Accounts submitted for execution: " + str(len(accounts)))
for account_id in accounts[:pipelines_to_run]:
execute_pipeline(session, str(account_id))
accounts.remove(account_id)
logger.info("Accounts remaining to be executed - ")
if accounts.isalnum():
logger.info(accounts)
logger.info(accounts)
return {"number_pending_accounts": len(accounts), "pending_accounts": accounts}

except Exception as error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,15 @@ def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, A

target_account_info = []
for account_id in target_accounts:
if account_id.isalnum():
logger.info(f"Building customization payload for {account_id}")
logger.info(f"Building customization payload for {account_id}")

try:
account_email = orgs_agent.get_account_email_from_id(account_id)
except ClientError as error:
if error.response["Error"]["Code"] == "AccountNotFoundException":
if account_id.isalnum():
logger.info(
f"Account with ID {account_id} does not exist or is suspended - ignoring"
)
logger.info(
f"Account with ID {account_id} does not exist or is suspended - ignoring"
)
target_accounts.remove(account_id)
continue
else:
Expand All @@ -89,9 +87,8 @@ def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, A
account_request=account_request,
control_tower_event={},
)
if account_payload.isalnum():
logger.info(f"Successfully generated payload: {account_payload}")
target_account_info.append(account_payload)
logger.info(f"Successfully generated payload: {account_payload}")
target_account_info.append(account_payload)

return {
"number_pending_accounts": len(target_accounts),
Expand Down

0 comments on commit 5303565

Please sign in to comment.