Skip to main content

AWS Session Management

This package contains

AwsSessionManagement - handles AWS Session with AWS Temp credentials by Assuming a given Role it renews the temp credentials when needed This library helps keeping boto3 clients with the fresh aws temp credentials

Usage:

This example shows how to manage the AWSRequestAuth object with the fresh temp credentials These credentials will be automatically refreshed by the AwsSessionManamagement class

Using the following libraries:

import requests import aws_requests_auth (https://github.com/DavidMuller/aws-requests-auth)


def get_auth(self):
    auth = None

    if self.awsSessionManagement is not None:
        aws_access_key_id, aws_secret_access_key, aws_session_token = self.awsSessionManagement.get_aws_credentials()
        if aws_access_key_id is not None and aws_secret_access_key is not None and aws_session_token is not None:
            logger.debug("got aws credentials, using for authentication")
            auth = AWSRequestsAuth(aws_access_key=aws_access_key_id,
                                   aws_secret_access_key=aws_secret_access_key,
                                   aws_token=aws_session_token,
                                   aws_host=f'{self.wmc_api_id}.execute-api.{self.wmc_api_region}.amazonaws.com',
                                   aws_region=self.wmc_api_region,
                                   aws_service='execute-api')
        else:
            logger.warning("ALL the retrieved aws credentials are None, not using authentication!")

    return auth


headers = {'content-type': 'application/json'}
json_data = {"a": 'a_value', "b": 'b_value'}
data = json.dumps(json_data)
response = requests.post(url=f"{self.api_gateway}/abc", auth=self.get_auth(), data=data, headers=headers)

OR Alternatively you can use AwsSessionManagement as follows:

def get_auth_request(aws_access_key_id, aws_secret_access_key, aws_session_token, aws_host, aws_region, aws_service):
    logger.info("creating/updating auth request ...")
    auth = AWSRequestsAuth(aws_access_key=aws_access_key_id,
                           aws_secret_access_key=aws_secret_access_key,
                           aws_token=aws_session_token,
                           aws_host=aws_host,
                           aws_region=aws_region,
                           aws_service=aws_service)
    logger.info("returning auth request")
    return auth



awsSessionManagement = AwsSessionManagement(role_arn='roleArnValue',
                                            external_id='externalIdValue',
                                            func=get_auth_request,
                                            func_params_dict={'aws_host': 'your_service_aws_host_name', 'aws_region': 'your_service_region', 'aws_service': 'your_aws_service_name'},
                                            role_session_name="CurrentSession")

# For example:
# aws_host = f'{self.api_gateway_id}.execute-api.{self.api_gateway_region}.amazonaws.com'
# aws_region = 'eu-west-1'
# aws_service = 'execute-api'

# get the auth request object with the temp aws credentials
auth = awsSessionManagement.get_func_res()
headers = {'Accept': 'application/json'}
response = requests.get(f"{self.api_gateway_url}/abc", auth=auth, headers=headers)


Release files for aws-session-management 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-session-management 0.0.3
File Size Uploaded
aws-session-management-0.0.3.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-session-management 0.0.3
File Interpreter ABI Platform
aws_session_management-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / aws-session-management-0.0.3.tar.gz

Download URL aws-session-management-0.0.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
579b6aad9b31d4a773a1b4c2646f7a957cfa9539b05a9b4f1d8bb5dcc0d503dd
BLAKE2b-256 checksum
How to use checksums
d49e9ddf6475fa85b4d65a743ea7b27e14051845a44a051597eccc78559561c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.6

Release files / aws_session_management-0.0.3-py3-none-any.whl

Download URL aws_session_management-0.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7edee968fd9f1770aab6470d03cfae25b5ee62df03195d18ff85349237910029
BLAKE2b-256 checksum
How to use checksums
2448643445e1b38e9aad68a20fb46957d68df0cea990f6fa447b5ccdf54d194c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.6

Release history Release notifications | RSS feed

0.0.8

1 release file

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page