Skip to main content

AWS infrastructure testing framework that supports multiple IAC tools.

Project description

B.AwsTestingFramework

A python based AWS infrastructure testing micro-framework.
It supports multiple IAC tools like AWS CDK and AWS CloudFormation.

Description

Creating infrastructure in AWS is quite hard. There are many nuances, pitfalls and "gotchas" that sometimes are awfully frustrating. Often some IAC code changes might result in some unexpected infrastructure changes. That is why the created infrastructure should have automated integration tests. This python based framework provides you basic functionality to help you write unit ant integration tests to test AWS infrastructure created via UI or via tools like AWS CDK.

The framework is based on pytest - a python based testing library. With that said, all pytest functionality and configs can be applied on this framework too.

The framework is easy to use with explicit examples for each IAC tool. Go to examples section and find which example suits you the most.

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

  • Python 3
  • Pytest
  • AWS CDK
  • AWS CloudFormation

Assumptions

The project assumes the following:

  • You have basic-good knowledge in python programming.
  • You have basic-good knowledge in AWS.
  • You have basic knowledge in testing.

Useful sources

Install

The project is built and uploaded to PyPi. Install it by using pip.

pip install b_aws_testing_framework

Or directly install it through source.

pip install .

Usage & Examples

The framework uses flexible credentials management. You can either set credentials in the constructor:

from b_aws_testing_framework.credentials import Credentials
Credentials(
    aws_access_key_id='key',
    aws_secret_access_key='secret',
    region_name='region'
)

Or you can set the environment:

set AWS_ACCESS_KEY_ID=key
set AWS_SECRET_ACCESS_KEY=key
set AWS_DEFAULT_REGION=region

And then in your python program:

from b_aws_testing_framework.credentials import Credentials
Credentials()

After setting the credentials you can set a global prefix. Global prefix is a globally accessible peace of string that can be used when naming AWS resources. This is extremely useful when running tests in CI/CD pipelines where we can have more than one parallel pipeline running. To access and manage a global prefix, import your testing manager and use these commands:

# Set a random string.
TestingManager.set_global_prefix()

# Create a resource with a unique name. E.g.
CdkStack(
    scope=scope,
    id=f'{TestingManager.get_global_prefix()}TestingStackId',
    stack_name=f'{TestingManager.get_global_prefix()}TestingStackName'
)

See the specific examples for specific tools:

Testing

The project has tests that can be run. Note, that tests are integration tests inherently because they test how resources are created in AWS environment. Since resources are created and tested in AWS you are subject for all the applicable charges while tests are being run.

Setting environment

Before running tests set environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION

Or:

  • AWS_PROFILE
  • AWS_DEFAULT_REGION

Running tests

Then run tests from a root directory with pytest python testing library.

Testing CloudFormation functionality:

pytest b_aws_testing_framework_test/tools/testing_with_cf

Testing Cloud Development Kit functionality:

pytest b_aws_testing_framework_test/tools/testing_with_cdk

Note that integration tests usually take a while to complete (from 5 to 30 minutes on average).

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

1.0.1

  • Update pipelines to fix "unclosed SSLSocket" warnings.

1.0.0

  • Upgrade CDK support from v1 to v2.
  • Upgrade GitHub pipelines checkout version from v2 to v3.
  • Upgrade biomapas/cicd-full image version to 5.0.0.

0.6.0

  • Too many bugs. Revert.

0.5.5

  • Warn if not cdk tool was found.

0.5.4

  • Make sure to exit after successful cdk execution.

0.5.3

  • Use "." instead of "source".

0.5.2

  • Execute cdk command in the same shell to preserve environment.

0.5.1

  • Allow running cdk command even though it might be now defined globally.

0.5.0

  • Pass config object to custom actions.

0.4.3

  • Fix version retrieval.

0.4.2

  • For the default SSM parameter name use "name" instead of "global prefix".

0.4.1

  • Make sure default SSM parameter is unique.

0.4.0

  • Add default SSM parameter for package version.

0.3.3.

  • Fix logging issues.
  • Run prehooks on session-start and session-finish.
  • Add more logging.

0.3.2

  • Fix warnings.

0.3.1

  • Bug fixes.

0.3.0

  • Add ability to specify custom deployment command in AWS CDK flow (destroy action).

0.2.0

  • Add ability to specify custom deployment command in AWS CDK flow (deploy action).

0.1.0

  • Allow to override the TestingStack's name.

0.0.24

  • Update boto version requirement.

0.0.23

  • Prettify example CDK project.

0.0.22

  • Add prefixes for CF outputs too.
  • Prettify CDK testing.

0.0.21

  • Add ability to specify session token.

0.0.20

  • Remove root path from cdk config in the documentation.

0.0.19

  • Make sure that Python path is propagated to the process.

0.0.18

  • Expose global prefix in the Testing stack.
  • Update example project.
  • Add ability to specify root project to fix import errors.
  • Updated tests.
  • Update documentation.

0.0.17

  • Improve documentation with better cdk project examples.
  • Add an example cdk project.
  • Remove test coverage.

0.0.13

  • Add testing stack for more convenient CF outputs management.
  • Update documentation.
  • Add docstrings.
  • Updates tests and conftest configuration files.
  • Version bump.

0.0.12

  • Add a flag to specify whether the infrastructure should be destroyed before creating a new one.

0.0.11

  • Add documentation about global prefix in readme.

0.0.10

  • Create a global prefix for unique resources.

0.0.9

  • Create github pipelines.
  • Update code.

0.0.8

  • Make sure CDK deploy works both on linux based systems and windows based systems.

0.0.7

  • Bug fix related to environment.

0.0.6

  • Update pytest dependency version.

0.0.5

  • Rethink how this framework should be used.

0.0.4

  • Fix imports.
  • Update examples.

0.0.3

  • Rename project.
  • Update gitignore and ignore idea files.
  • Update MANIFEST.
  • Move examples to a documentation folder.

0.0.2

  • Add hyperlinks for examples.

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

b_aws_testing_framework-1.0.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

b_aws_testing_framework-1.0.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file b_aws_testing_framework-1.0.1.tar.gz.

File metadata

File hashes

Hashes for b_aws_testing_framework-1.0.1.tar.gz
Algorithm Hash digest
SHA256 81fca5343e16c8d59ec33832b772202327ffbe0ca205c4996522d842871394d6
MD5 19ec5a200bccde8c1835bd45abf6b14b
BLAKE2b-256 9ddd08f699420962887f814c72c434a3df1479577ea82faf88efdc6050f6ce2d

See more details on using hashes here.

File details

Details for the file b_aws_testing_framework-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for b_aws_testing_framework-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0c43a5fc0dfdfec081a746ff5e2932505721c03de79c7ae03f108a63731effc
MD5 b23aeed38cc66ebdf66b46f41818c234
BLAKE2b-256 7236f6660ebe099718190038bd7959de18cb0d2ffcf4118b64d37c8242c3526a

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