Skip to content

Commit

Permalink
Workaround AWS session error in multi-thread process
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmitrofan committed Jun 4, 2020
1 parent a2f6c12 commit cd47e8c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.7-alpine

RUN pip install stackuchin==1.3.0
RUN pip install stackuchin==1.4.0

VOLUME /project

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

here = path.abspath(path.dirname(__file__))

current_version = str('1.3.0')
current_version = str('1.4.0')

# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
Expand Down
2 changes: 1 addition & 1 deletion src/stackuchin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):

# noinspection PyMethodMayBeStatic
def version(self):
print("1.3.0")
print("1.4.0")

# noinspection PyMethodMayBeStatic
def create(self):
Expand Down
13 changes: 7 additions & 6 deletions src/stackuchin/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ def create(profile_name, stack_file, stack_name, secret, slack_webhook_url,
exit(1)

# Get auth
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)
if not from_pipeline:
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)

# Verify integrity of stack
stacks = None
Expand Down
14 changes: 8 additions & 6 deletions src/stackuchin/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ def delete(profile_name, stack_file, stack_name,
exit(1)

# Get auth
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)
if not from_pipeline:
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)

# Verify integrity of stack
stacks = None
try:
Expand Down
4 changes: 4 additions & 0 deletions src/stackuchin/start_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yaml
import concurrent.futures
import boto3


from stackuchin.create import create
Expand Down Expand Up @@ -64,6 +65,9 @@ def start_pipeline(profile_name, stack_file, pipeline_file,
if 'pipeline_type' in pipeline:
pipeline_type = pipeline['pipeline_type']

if profile_name is not None:
boto3.setup_default_session(profile_name=profile_name)

if pipeline_type == "sequential":
# First create new stacks (if any)
if "create" in pipeline:
Expand Down
14 changes: 8 additions & 6 deletions src/stackuchin/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ def update(profile_name, stack_file, stack_name, secret, slack_webhook_url,
exit(1)

# Get auth
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)
if not from_pipeline:
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as exc:
print(exc)
exit(1)

# Verify integrity of stack
stacks = None
try:
Expand Down
9 changes: 0 additions & 9 deletions src/stackuchin/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@


def current_user(profile_name):
if profile_name is not None:
try:
boto3.setup_default_session(profile_name=profile_name)
except Exception as e:
print(e)
exit(1)
sts = boto3.client('sts')
return sts.get_caller_identity()['Arn']

Expand Down Expand Up @@ -249,9 +243,6 @@ def alert(stack_name, error=None, stack_region=None, stack_account=None, action=
profile_name=None, slack_webhook_url=None):

if slack_webhook_url is not None:
if profile_name is not None:
boto3.setup_default_session(profile_name=profile_name)

iam_user = current_user(profile_name)
action = str(action).upper()

Expand Down

0 comments on commit cd47e8c

Please sign in to comment.