multacdkrecipies - Custom CDK Constructs for rapid development
- Designed to facilitate AWS CDK usage in Python CDK Apps by creating high-level constructs that help development in Serverless Applications.
- Designed to be used like a regular Python CDK application.
- Designed to expose resources over Python Classes properties, keeping flexibility in the CDK application.
- Designed to configure constructs by passing settings in Python dictionaries.
Installation
- Install with
pip$ pip install multacdkrecipies
Usage
config.py- Set configuration for the multacdkrecipies CDK Constructs.
"LAMBDA_LAYER_CONFIG": {
"identifier": "api_gateway",
"layer_name": "api_gateway_venv_layer",
"description": "Lambda Layer containing local Python's Virtual Environment needed for the handler functions.",
"layer_runtimes": ["PYTHON_3_7"],
}
API_CONFIG = {
"api": {
"apigateway_name": "device_gateway",
"apigateway_description": "API Gateway used for Multa Device Agents to be associated to the AWS IoT",
"authorizer_function": {
"origin": {
"lambda_name": "authorizer",
"description": "Authorizer Lambda function for API resources.",
"code_path": "./src/functions/",
"runtime": "PYTHON_3_7",
"handler": "authorizer.lambda_handler",
"layers": [],
"timeout": 10,
"environment_vars": {
"LOG_LEVEL": "INFO",
},
"iam_actions": ["*"],
}
},
"settings": {
"proxy": False,
"custom_domain": {
"domain_name": "cvm-agent.dev.multa.io",
"certificate_arn": "arn:aws:acm:us-east-1:112646120612:certificate/48e19da0-71a4-417a-9247-c02ef100749c",
},
"default_cors_options": {"allow_origins": ["*"], "options_status_code": 200},
"default_http_methods": ["GET"],
"default_stage_options": {"metrics_enabled": True, "logging_level": "INFO"},
"default_handler": {
"lambda_name": "device_default_handler",
"description": "Handler Lambda for API Gateway root resource.",
"code_path": "./src/functions/",
"runtime": "PYTHON_3_7",
"handler": "main_handler.lambda_handler",
"layers": [],
"timeout": 10,
"environment_vars": {
"LOG_LEVEL": "INFO"
},
"iam_actions": ["*"],
},
},
"resource_trees": [
{
"resource_name": "demo",
"methods": ["POST"],
"handler": {
"lambda_name": "device_gateway_handler",
"description": "Handler Lambda for API Gateway demo resource.",
"code_path": "./src/functions/",
"runtime": "PYTHON_3_7",
"handler": "demo_handler.lambda_handler",
"layers": [],
"timeout": 10,
"environment_vars": {
"LOG_LEVEL": "INFO",
},
"iam_actions": ["*"],
},
},
],
}
}
stack.py- Create the CDK App Stack by using multacdkrecipies CDK Constructs with the configuration defined above.
from aws_cdk import core
from multacdkrecipies import (
AwsApiGatewayLambdaPipes,
AwsLambdaLayerVenv,
)
from config import API_CONFIG, LAMBDA_LAYER_CONFIG
class ApiStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, config=None, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Define Lambda Layer to be used by the API Resources Lambda handlers.
self._device_gateway_api_lambdalayer = AwsLambdaLayerVenv(
self,
id="GatewayApiLayer-dev",
prefix="gateway_api",
environment="dev",
configuration=LAMBDA_LAYER_CONFIG,
)
layer_arn = self._device_gateway_api_lambdalayer.lambda_layer.layer_version_arn
# Add Lambda Layer ARN to the Lambda Functions configuration.
API_CONFIG["api"]["authorizer_function"]["origin"]["layers"].append(layer_arn)
API_CONFIG["api"]["settings"]["default_handler"]["layers"].append(layer_arn)
API_CONFIG["api"]["resource_trees"]:
function["handler"]["layers"].append(layer_arn)
# Define Lambda Functions handlers for the API Gateway resources.
self._gateway_api = AwsApiGatewayLambdaPipes(
self,
id="GatewayApiGw-dev",
prefix="gateway_api",
environment="dev",
configuration=API_CONFIG,
)
app.py- Initialize the CDK App like a regular CDK App.
from aws_cdk import core
from stack import ApiStack
app = core.App()
ApiStack(app, id=f"GatewayApiStack-dev")
app.synth()
How to Contribute
- Clone repo and create a new branch:
$ git checkout https://github.com/u93/multacdkrecipies -b ${BRANCH_NAME}. - Make changes and test
- Submit Pull Request with comprehensive description of changes
Acknowledgements
- @sfernandezf for all the help and introduce me to AWS.
- Mauricio Villaescusa for introduce me to CDK and listen all my dummy ideas.
- @destradar93 and @yoya93 for all the help testing and using this project.
Donations
This is free, open-source software, so no need to donate anything except knowledge... Contributions are good enough :)
Metadata
Release files for multacdkrecipies 0.2.8.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 | Provenance | Actions |
|---|---|---|---|---|
| multacdkrecipies-0.2.8.3.tar.gz | 39.7 kB | Without provenance | Details for multacdkrecipies-0.2.8.3.tar.gz |
Release files / multacdkrecipies-0.2.8.3.tar.gz
| Download URL | multacdkrecipies-0.2.8.3.tar.gz |
|---|---|
| Size | 39.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
312bf42e4d872a28991ce82282924163bf0282aaee0503d28f2d6954b211bfec
|
|
BLAKE2b-256 checksum How to use checksums |
ed7f026f404e136ca57436c249d85d94ec85e60ab5406185604af143b9a5383e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Security for multacdkrecipies 0.2.8.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.