Skip to content

Commit

Permalink
Use a boto session rather than global client
Browse files Browse the repository at this point in the history
  • Loading branch information
adammcdonagh committed Oct 20, 2023
1 parent d9c102e commit 6e721bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/opentaskpy/addons/aws/remotehandlers/ecsfargate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def __init__(self, spec: dict):
if os.environ.get("AWS_ENDPOINT_URL"):
kwargs["endpoint_url"] = os.environ.get("AWS_ENDPOINT_URL")

self.ecs_client = boto3.client("ecs", **kwargs)
session = boto3.session.Session()

self.ecs_client = session.client("ecs", **kwargs)

def kill(self) -> None:
"""Kill the fargate task function.
Expand Down
11 changes: 7 additions & 4 deletions tests/test_remotehandler_ecsfargate_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import botocore.exceptions
import opentaskpy.otflogging
import pytest
from moto import mock_ecs
from opentaskpy.taskhandlers import execution

from opentaskpy.addons.aws.remotehandlers.ecsfargate import FargateTaskExecution
Expand Down Expand Up @@ -83,13 +82,15 @@ def credentials_aws_dev():
del os.environ["AWS_ENDPOINT_URL"]


def create_ecs_cluster():
def create_ecs_cluster(credentials_aws_dev):
# Print all env vars that start with AWS
for key, value in os.environ.items():
if key.startswith("AWS"):
print(f"{key}: {value}")

client = boto3.client("ecs")
session = boto3.session.Session()

client = session.client("ecs")
# Check to see if the ECS cluster exists
try:
response = client.describe_clusters(clusters=["test_cluster"])
Expand All @@ -108,7 +109,9 @@ def create_ecs_cluster():


def create_fargate_task():
client = boto3.client("ecs")
session = boto3.session.Session()

client = session.client("ecs")

# Check to see if the task definition exists
try:
Expand Down

0 comments on commit 6e721bc

Please sign in to comment.