diff --git a/CHANGELOG.md b/CHANGELOG.md index 3349b59..0978600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Changed +- Added support for AWS Profile + ## [0.1.9][] - 2023-04-03 [0.1.9]: https://github.com/awslabs/aws-az-failure-chaostoolkit/tree/v0.1.9 diff --git a/azchaosaws/__init__.py b/azchaosaws/__init__.py index ef8e36b..8145bf9 100644 --- a/azchaosaws/__init__.py +++ b/azchaosaws/__init__.py @@ -37,6 +37,7 @@ def client(resource_name: str, configuration: Configuration = None): params = dict() region = configuration.get("aws_region") + aws_profile_name = configuration.get("aws_profile_name") if not region: region = os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")) if not region: @@ -46,9 +47,14 @@ def client(resource_name: str, configuration: Configuration = None): logger.debug("Using AWS region '{}'".format(region)) params["region_name"] = region - session = boto3.Session(**params) - - return session.client(resource_name, **params) + if boto3.DEFAULT_SESSION is None: + boto3.setup_default_session(profile_name=aws_profile_name, **params) + logger.debug( + "Client will be using profile '{}'".format( + aws_profile_name or "default" + ) + ) + return boto3.client(resource_name, **params) ###############################################################################