core-aws-cdk
This project contains common elements and constructs to create infrastructure in AWS using AWS CDK with Python.
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
Install required libraries:
pip install --upgrade pip
pip install virtualenv
Create Python virtual environment:
virtualenv --python=python3.12 .venv
Activate the virtual environment:
source .venv/bin/activate
Install packages
pip install .
pip install -e ".[dev]"
Check tests and coverage
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):
pytest tests/functional/check_lambda_creation.py
Run a specific test:
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):
pytest tests/functional/*.py -n 2
IMPORTANT: Functional tests deploy real resources to AWS and may incur costs and require AWS credentials configured.
Prerequisites
AWS credentials configured.
CDK CLI installed npm install -g aws-cdk.
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
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
npm install -g aws-cdk@latest
cdk --version
Issue: Node.js version warning
Solution: Ensure Node.js v20 or v22 is installed and accessible
node --version
which node
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Write tests for new functionality
Ensure all tests pass with full coverage: python manager.py run-coverage
Run linters: ty check core_aws_cdk, ruff check ., mypy core_aws_cdk, pyright core_aws_cdk, pylint core_aws_cdk
Run security checks: bandit -r core_aws_cdk, pip-audit
Submit a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
Support
For questions or support, please open an issue on GitLab or contact the maintainers.
Metadata
Release files for core-aws-cdk 3.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| core_aws_cdk-3.1.3.tar.gz | 37.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| core_aws_cdk-3.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 78.0 kB
Release files / core_aws_cdk-3.1.3.tar.gz
| Download URL | core_aws_cdk-3.1.3.tar.gz |
|---|---|
| Size | 37.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d15b6136d7b717aa45b4a28968befc5031bdc8b4d3f76f34f56a1ccd1aac4be2
|
|
BLAKE2b-256 checksum How to use checksums |
0a77d0630e0c2622899c8278acd742ded7b9ca938d3bf2ea805a84ad73473c68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / core_aws_cdk-3.1.3-py3-none-any.whl
| Download URL | core_aws_cdk-3.1.3-py3-none-any.whl |
|---|---|
| Size | 40.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51b7019aa114882c0d27f8c7a8043bfdb5fc1aba637d94bdcf338113626fb537
|
|
BLAKE2b-256 checksum How to use checksums |
55eb3cd79d00c492fa068f7d063fb8defbc9f34db7b1058bf0c746eed5ac6a62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|