Skip to content

Commit

Permalink
Consistent retries, fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartW committed Oct 20, 2021
1 parent c259bc8 commit 80ee274
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 41 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ test:
lint:
# Linter performs static analysis to catch latent bugs
find src/ -iname "*.py" -not -path ".aws-sam/*" | xargs pylint --rcfile .pylintrc

build:
sam build -u

deploy:
sam deploy --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
48 changes: 24 additions & 24 deletions src/account_processing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,21 +474,21 @@ Resources:
"Type": "Task",
"Resource": "${AccountAliasConfigFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "ConfigureAccountTags"
},
"CreateAccount": {
"Type": "Task",
"Resource": "${CreateAccountFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "WaitFor10Seconds"
},
Expand All @@ -501,32 +501,32 @@ Resources:
"Type": "Task",
"Resource": "${RegisterAccountForSupportFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "ConfigureAccountAlias"
},
"ConfigureAccountTags": {
"Type": "Task",
"Resource": "${AccountTagConfigFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "ConfigureAccountOU"
},
"ConfigureAccountOU": {
"Type": "Task",
"Resource": "${AccountOUConfigFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "DeleteDefaultVPCChoice"
},
Expand All @@ -545,10 +545,10 @@ Resources:
"Type": "Task",
"Resource": "${GetAccountRegionsFunction.Arn}",
"Retry": [{
"ErrorEquals": ["RetryError"],
"IntervalSeconds": 10,
"BackoffRate": 1.0,
"MaxAttempts": 20
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 30
}],
"Next": "DeleteDefaultVPCMap"
},
Expand Down
4 changes: 2 additions & 2 deletions src/lambda_codebase/account_processing/create_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import os
from aws_xray_sdk.core import patch_all
patch_all()
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")
import boto3

patch_all()
ADF_ROLE_NAME = os.getenv("ADF_ROLE_NAME")

def create_account(account, adf_role_name, org_client):
allow_billing = "ALLOW" if account.get("allow_billing", False) else "DENY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import json
import os
from typing import Tuple
from aws_xray_sdk.core.patcher import patch
import yaml

from aws_xray_sdk.core import xray_recorder, patch_all

patch_all()

import boto3
from aws_xray_sdk.core import patch_all
from organizations import Organizations

import boto3
patch_all()

ACCOUNT_MANAGEMENT_STATEMACHINE = os.getenv("ACCOUNT_MANAGEMENT_STATEMACHINE_ARN")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
"""

from enum import Enum
from logger import configure_logger
from aws_xray_sdk.core import patch_all
patch_all()

import boto3
from botocore.exceptions import ClientError, BotoCoreError
from botocore.config import Config

from logger import configure_logger
from aws_xray_sdk.core import patch_all

LOGGER = configure_logger(__name__)

patch_all()

class SupportLevel(Enum):
BASIC = "basic"
Expand Down
4 changes: 2 additions & 2 deletions src/lambda_codebase/account_processing/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyyaml
pyyaml>=5.4.1
wrapt==1.12
aws-xray-sdk
aws-xray-sdk==2.8.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

import boto3
from botocore.stub import Stubber

from aws_xray_sdk import global_sdk_config
from ..configure_account_alias import create_account_alias

global_sdk_config.set_sdk_enabled(False)

# pylint: disable=W0106
def test_account_alias():

test_account = {"Id": 1234567890, "alias": "MyCoolAlias"}
iam_client = boto3.client("iam")
stubber = Stubber(iam_client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import unittest
import boto3
from botocore.stub import Stubber
from aws_xray_sdk import global_sdk_config

from ..create_account import create_account

global_sdk_config.set_sdk_enabled(False)

# pylint: disable=W0106
class SuccessTestCase(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ deps =
-r{toxinidir}/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/requirements.txt
-r{toxinidir}/src/lambda_codebase/initial_commit/requirements.txt
-r{toxinidir}/src/lambda_codebase/account/requirements.txt
-r{toxinidir}/src/lambda_codebase/account_processing/requirements.txt
commands =
make test
make lint

0 comments on commit 80ee274

Please sign in to comment.