Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from venkivijay/feat-aws-profile
Browse files Browse the repository at this point in the history
Add support for AWS profile
  • Loading branch information
farhanangullia authored Oct 21, 2023
2 parents e79f64d + c9253e5 commit ef35af4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions azchaosaws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


###############################################################################
Expand Down

0 comments on commit ef35af4

Please sign in to comment.