Metadata-Version: 2.4
Name: core-aws-cdk
Version: 3.1.3
Summary: This project contains the commons elements to create infrastructure in AWS using AWS CDK...
Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
Maintainer: Alejandro Cora González
License-Expression: MIT
Project-URL: Homepage, https://gitlab.com/bytecode-solutions/infrastructure/core-aws-cdk
Project-URL: Repository, https://gitlab.com/bytecode-solutions/core/core-aws-cdk
Project-URL: Documentation, https://core-aws-cdk.readthedocs.io/en/latest/
Project-URL: Issues, https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/issues
Project-URL: Changelog, https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/blob/master/CHANGELOG.md
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 5 - Production/Stable
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: aws-cdk-lib>=2.195.0
Requires-Dist: boto3>=1.34.0
Requires-Dist: core-mixins>=3.2.0
Provides-Extra: dev
Requires-Dist: core-dev-tools>=2.1.0; extra == "dev"
Requires-Dist: core-tests>=2.3.0; extra == "dev"
Dynamic: license-file

core-aws-cdk
===============================================================================

This project contains common elements and constructs to create infrastructure
in AWS using AWS CDK with Python.

===============================================================================

.. image:: https://static.pepy.tech/personalized-badge/core-aws-cdk?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads
    :target: https://pepy.tech/projects/core-aws-cdk
    :alt: PyPI Downloads

.. image:: https://img.shields.io/pypi/pyversions/core-aws-cdk.svg
    :target: https://pypi.org/project/core-aws-cdk/
    :alt: Python Versions

.. image:: https://img.shields.io/badge/license-MIT-blue.svg
    :target: https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/blob/main/LICENSE
    :alt: License

.. image:: https://gitlab.com/bytecode-solutions/core/core-aws-cdk/badges/release/pipeline.svg
    :target: https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/pipelines
    :alt: Pipeline Status

.. image:: https://readthedocs.org/projects/core-aws-cdk/badge/?version=latest
    :target: https://readthedocs.org/projects/core-aws-cdk/
    :alt: Docs Status

.. image:: https://img.shields.io/badge/security-bandit-yellow.svg
    :target: https://github.com/PyCQA/bandit
    :alt: Security

|


Features
===============================================================================

* **Base Stacks**: Pre-configured CDK stacks with tagging support
* **Lambda Functions**: Simplified Lambda creation with automatic packaging
* **S3 Buckets**: S3 bucket creation with security best practices
* **SQS Queues**: Queue creation with dead-letter queue support
* **SNS Topics**: Topic creation with subscription management
* **Network Stack**: VPC and networking resource management
* **ZIP Asset Packaging**: Automatic Lambda ZIP creation with dependencies


Quick Start
===============================================================================

Setting Up Environment
-------------------------------------------------------------------------------

1. Install required libraries:

.. code-block:: bash

    pip install --upgrade pip
    pip install virtualenv

2. Create Python virtual environment:

.. code-block:: bash

    virtualenv --python=python3.12 .venv

3. Activate the virtual environment:

.. code-block:: bash

    source .venv/bin/activate

Install packages
-------------------------------------------------------------------------------

.. code-block:: bash

    pip install .
    pip install -e ".[dev]"

Check tests and coverage
-------------------------------------------------------------------------------

.. code-block:: shell

    python manager.py run-tests
    python manager.py run-tests --test-type integration
    python manager.py run-coverage

    # Having proper AWS credentials...
    python manager.py run-tests --test-type functional --pattern "*.py"

Note: bare ``pytest``/``pytest -n auto`` correctly discovers and runs the
``tests_*.py`` unit suite. ``check_*.py`` functional tests are deliberately
excluded from auto-discovery, since they deploy real AWS resources; pass
them to ``pytest`` as explicit paths, which is also how to run them with
parallelism ``manager.py`` doesn't offer:

Run a specific functional test file (requires AWS credentials):

.. code-block:: shell

    pytest tests/functional/check_lambda_creation.py

Run a specific test:

.. code-block:: shell

    pytest tests/functional/check_lambda_creation.py::TestLambdaCreation::test_create_and_invoke_lambda_with_inline_code

Run a few functional test files with limited parallelism (recommended, to avoid AWS rate limits):

.. code-block:: shell

    pytest tests/functional/*.py -n 2


**IMPORTANT:** Functional tests deploy real resources to AWS and may incur costs and
require AWS credentials configured.


Prerequisites
-------------------------------------------------------------------------------

1. AWS credentials configured.
2. CDK CLI installed `npm install -g aws-cdk`.
3. Required AWS permissions:
   * Lambda (create, invoke, delete)
   * S3 (create bucket, put/get objects, delete)
   * SNS (create topic, publish)
   * SQS (create queue, send/receive messages)
   * CloudFormation (create/update/delete stacks)
   * IAM (create roles and policies)

Important Notes:

* Tests automatically clean up resources after completion
* Each test uses temporary directories and unique resource names
* Tests include 10-minute timeouts for deployment and cleanup
* All logs captured with DEBUG level for troubleshooting


Architecture Examples
===============================================================================

Complete SNS → SQS → Lambda → S3 Integration
-------------------------------------------------------------------------------

.. code-block:: python

    from aws_cdk import App, Environment, Duration, CfnOutput
    from aws_cdk.aws_lambda import Code, Runtime
    from aws_cdk.aws_lambda_event_sources import SqsEventSource
    from aws_cdk.aws_sns_subscriptions import SqsSubscription
    from core_aws_cdk.stacks.lambdas import BaseLambdaStack
    from core_aws_cdk.stacks.s3 import BaseS3Stack
    from core_aws_cdk.stacks.sns import BaseSnsStack
    from core_aws_cdk.stacks.sqs import BaseSqsStack

    class IntegratedStack(
        BaseSnsStack,
        BaseSqsStack,
        BaseLambdaStack,
        BaseS3Stack
    ):
        """ My Custom Stack """

    app = App()

    stack = IntegratedStack(
        app,
        "IntegratedStack",
        env=Environment(
            account="123456789",
            region="us-east-1"
        ))

    # Create S3 bucket
    bucket = stack.create_bucket(
        bucket_id="DataBucket",
        bucket_name=None  # Auto-generate
    )

    # Create SQS queue with DLQ
    queue = stack.create_sqs_queue(
        queue_id="ProcessQueue",
        queue_name="process-queue",
        with_dlq=True,
        dlq_id="ProcessQueueDLQ",
        max_receive_count=3
    )

    # Create SNS topic
    topic = stack.create_sns_topic(
        topic_id="EventTopic",
        topic_name="event-topic"
    )

    # Subscribe queue to topic
    topic.add_subscription(SqsSubscription(queue))

    # Create Lambda processor
    lambda_function = stack.create_lambda(
        function_id="Processor",
        handler="handler.lambda_handler",
        code=Code.from_asset("./lambda"),
        runtime=Runtime.PYTHON_3_12,
        timeout=Duration.minutes(5),
        environment={"BUCKET_NAME": bucket.bucket_name}
    )

    # Configure SQS as Lambda trigger
    lambda_function.add_event_source(SqsEventSource(queue))

    # Grant permissions
    bucket.grant_write(lambda_function)

    # Export outputs
    CfnOutput(stack, "TopicArn", value=topic.topic_arn)
    CfnOutput(stack, "BucketName", value=bucket.bucket_name)

    app.synth()


Issue: CDK version mismatch
-------------------------------------------------------------------------------

**Solution:** Ensure CDK CLI version matches library version

.. code-block:: shell

    npm install -g aws-cdk@latest
    cdk --version


Issue: Node.js version warning
-------------------------------------------------------------------------------

**Solution:** Ensure Node.js v20 or v22 is installed and accessible

.. code-block:: shell

    node --version
    which node


Contributing
===============================================================================

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Write tests for new functionality
4. Ensure all tests pass with full coverage: ``python manager.py run-coverage``
5. Run linters: ``ty check core_aws_cdk``, ``ruff check .``, ``mypy core_aws_cdk``, ``pyright core_aws_cdk``, ``pylint core_aws_cdk``
6. Run security checks: ``bandit -r core_aws_cdk``, ``pip-audit``
7. Submit a pull request

License
===============================================================================

This project is licensed under the MIT License. See the LICENSE file for details.

Links
===============================================================================

* **Documentation:** https://core-aws-cdk.readthedocs.io/en/latest/
* **Repository:** https://gitlab.com/bytecode-solutions/core/core-aws-cdk
* **Issues:** https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/issues
* **Changelog:** https://gitlab.com/bytecode-solutions/core/core-aws-cdk/-/blob/master/CHANGELOG.md
* **PyPI:** https://pypi.org/project/core-aws-cdk/

Support
===============================================================================

For questions or support, please open an issue on GitLab or contact the maintainers.

Authors
===============================================================================

* **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
