Skip to main content

Package that enables deployment of AWS CDK stacks in parallel.

Project description

B.CfnCustomUserPoolAuthorizer

An AWS CDK resource that mimics original UserPoolAuthorizer resource.

Description

This is a custom user pool authorizer used to protect API endpoints. It has exactly the same functionality and purpose as the original UserPoolAuthorizer. The main reason why you would want to use this custom authorizer instead of a default one - is that this custom authorizer can resolve user pool region, id, and client id from SSM parameters (AWS Systems Manager Parameter Store). This way your stacks no longer need a dependency to a stack containing user pool instance.

Remarks

Biomapas aims to modernise life-science industry by sharing its IT knowledge with other companies and the community. This is an open source library intended to be used by anyone. Improvements and pull requests are welcome.

Related technology

  • Python3
  • AWS CDK
  • AWS CloudFormation
  • AWS Cognito
  • AWS Cognito User Pool
  • AWS API Gateway
  • AWS API Gateway Authorizer

Assumptions

This project assumes you are an expert in infrastructure-as-code via AWS CloudFormation and AWS CDK. You must clearly understand how AWS API Gateway endpoints are protected with Authorizers / Custom Authorizers and how it is managed via CloudFormation or CDK. You must also understand the pain-points of stack dependencies and dependencies between microservices in general (which this package aims to solve).

  • Excellent knowledge in IaaC (Infrastructure as a Code) principles.
  • Excellent knowledge in Cognito, User Pool, API Gateway, Authorizers.
  • Good experience in AWS CDK and AWS CloudFormation.
  • Good Python skills and basis of OOP.

Useful sources

Install

Before installing this library, ensure you have these tools setup:

  • Python / Pip
  • AWS CDK
  • Docker

To install this project from source run:

pip install .

Or you can install it from a PyPi repository:

pip install b-cfn-custom-userpool-authorizer

Usage & Examples

from aws_cdk.core import Stack
from aws_cdk.aws_cognito import UserPool, UserPoolClient
from aws_cdk.aws_apigatewayv2 import CfnApi

from b_cfn_custom_userpool_authorizer.config.user_pool_config import UserPoolConfig
from b_cfn_custom_userpool_authorizer.user_pool_custom_authorizer import UserPoolCustomAuthorizer

# Create user pool and client.
pool = UserPool(...)
client = UserPoolClient(...)

# Create an API Gateway API.
api = CfnApi(...)

# Create custom authorizer and use it in your endpoints (CfnRoute).
authorizer = UserPoolCustomAuthorizer(
    scope=Stack(...),
    name='MyCustomAuthorizer',
    api=api,
    user_pool_config=UserPoolConfig(
        user_pool_id=pool.user_pool_id,
        user_pool_region=pool.stack.region,
        user_pool_client_id=client.user_pool_client_id
    )
)

Testing

This package has integration tests based on pytest. To run tests simply run:

pytest b_cfn_custom_userpool_authorizer_test/integration/tests

Contribution

Found a bug? Want to add or suggest a new feature? Contributions of any kind are gladly welcome. You may contact us directly, create a pull-request or an issue in github platform. Lets modernize the world together.

Release history

0.0.14

  • Simplify logging with pytest.

0.0.13

  • Update B.LambdaLayerCommon dependency.

0.0.12

  • Add more integration tests.
  • Update b_lambda_layer_common dependency.

0.0.11

  • Add readme.

0.0.10

  • Add tests.

0.0.9

  • Enable caching.

0.0.8

  • Fix testing configuration.

0.0.7

  • Success! Authorizer can now successfully authorize tokens.

0.0.6

  • First attempt to verify cognito user pool JWT token.

0.0.5

  • Still work in progress. Requests and tests work.
  • Checking the actual access token - in progress.

0.0.3

  • Work in progress. Added integration testing files.

0.0.1

  • Initial build.

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

Built Distribution

File details

Details for the file b_cfn_custom_userpool_authorizer-0.0.14.tar.gz.

File metadata

  • Download URL: b_cfn_custom_userpool_authorizer-0.0.14.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for b_cfn_custom_userpool_authorizer-0.0.14.tar.gz
Algorithm Hash digest
SHA256 9b3904848b707524ed571c396347aeafdb98cac23a897c51fd6cdeb281799340
MD5 d13af6d7bd57bc5393f738f15211c540
BLAKE2b-256 ca2ffe8582c840848dbcc48d08887039b94f8b741ff50cdce2cb2f46b501a48c

See more details on using hashes here.

File details

Details for the file b_cfn_custom_userpool_authorizer-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: b_cfn_custom_userpool_authorizer-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for b_cfn_custom_userpool_authorizer-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 75f0af19512f0cbe5812a8ba8335e42d34a78e2d9ea3f7f9ae7a486a70a7fa5b
MD5 3d81d3ab6cbf091f49ac11208cbfe06e
BLAKE2b-256 afce1ffb06aa7d842e4ae2660ebd8ef53c2a48613fa91bd8fffabf9dabf67210

See more details on using hashes here.

Supported by

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