Skip to main content

Provides AWS authentication middlewares to be used with aiohttp

Project description

aiohttp-aws-auth

Overview

This module provides AWS Signature Version 4 (SigV4) authentication for aiohttp through two primary middleware classes:

  • AwsSigV4Auth: For direct AWS credential authentication
  • AwsSigV4AssumeRoleAuth: For authentication using AWS IAM Role assumption

Features

  • Simple integration with aiohttp
  • Support for both synchronous and asynchronous authentication
  • AWS SigV4 signing for API requests
  • IAM Role assumption with configurable duration
  • Credential expiration and automatic refresh
  • Flexible configuration options

Installation

Install the package using pip:

pip install aiohttp-aws-auth

Usage

Basic AWS Credentials Authentication

import aiohttp
from aiohttp_aws_auth import AwsSigV4Auth, AwsCredentials

# Create AWS credentials
credentials = AwsCredentials(
    access_key='YOUR_ACCESS_KEY',
    secret_key='YOUR_SECRET_KEY'
)

# Create an authentication middleware
aws_auth_middleware = AwsSigV4Auth(
    credentials=credentials,
    region='us-west-2',
    service='execute-api',
)


# Make a request
async with ClientSession(middlewares=(aws_auth_middleware,)) as session:
    resp = await session.get("https://your-api-endpoint.com")

IAM Role Assumption

import aioboto3
from aiohttp_aws_auth import AwsSigV4AssumeRoleAuth

# Create async AWS session
session = aioboto3.Session()

# Create an authentication middleware
aws_auth_middleware = AwsSigV4AssumeRoleAuth(
    region='us-west-2',
    role_arn='arn:aws:iam::123456789012:role/YourRole',
    session=session,
    duration=timedelta(hours=1),
)

# Make an async request
async with ClientSession(middlewares=(aws_auth_middleware,)) as session:
    resp = await session.get("https://your-api-endpoint.com")

Configuration Options

AwsSigV4Auth

  • credentials: AWS credentials object
  • region: AWS region
  • service: AWS service name (default: 'execute-api')

AwsSigV4AssumeRoleAuth

  • region: AWS region
  • role_arn: IAM Role ARN to assume
  • service: AWS service name (default: 'execute-api')
  • session: Synchronous boto3 session
  • async_session: Asynchronous aioboto3 session
  • duration: Credential validity duration (default: 1 hour)
  • refresh_buffer: Time before expiration to refresh credentials (default: 0 seconds)

Dependencies

  • aiohttp
  • aioboto3 (only needed when using AwsSigV4AssumeRoleAuth)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp_aws_auth-0.0.2.tar.gz (64.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_aws_auth-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_aws_auth-0.0.2.tar.gz.

File metadata

  • Download URL: aiohttp_aws_auth-0.0.2.tar.gz
  • Upload date:
  • Size: 64.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiohttp_aws_auth-0.0.2.tar.gz
Algorithm Hash digest
SHA256 706398240ae4e0b43de5b31e0491d256a376c08e5373f05d4a90b307266bae28
MD5 769bee1042cb5f541065e5745e4c188d
BLAKE2b-256 45a3a9ce9b9bd0d2233fcdbef3e216ed8c888fa28add3b300978a5183feaee30

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_aws_auth-0.0.2.tar.gz:

Publisher: release.yml on jammymalina/aiohttp-aws-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiohttp_aws_auth-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_aws_auth-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a441e0c2990e1f8151721dcc182e454c67f07e23d90217cb701025b8ecfe14ba
MD5 18759db03e013ee5ea489d446655b6b4
BLAKE2b-256 f0123a2bf8db1cbedfe1e340c30fef29f1f5a8e7c438dc2c19496a84ccf99fa0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_aws_auth-0.0.2-py3-none-any.whl:

Publisher: release.yml on jammymalina/aiohttp-aws-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page