Skip to main content

No project description provided

Project description

CloudFormation CLI

AWS CloudFormation CLI

The CloudFormation CLI (cfn) allows you to author your own resource providers, hooks, and modules that can be used by CloudFormation.

Usage

Documentation

Primary documentation for the CloudFormation CLI can be found at the AWS Documentation site.

Installation

This tool can be installed using pip from the Python Package Index (PyPI). It requires Python 3. For resource and hook types, the tool requires at least one language plugin. Language plugins are not needed to create a module type. The language plugins are also available on PyPI and as such can be installed all at once:

pip install cloudformation-cli cloudformation-cli-java-plugin cloudformation-cli-go-plugin cloudformation-cli-python-plugin cloudformation-cli-typescript-plugin

Command: init

To create a project in the current directory, use the init command. A wizard will guide you through the creation.

cfn init

Command: generate

To refresh auto-generated code, use the generate command. Usually, plugins try to integrate this command in the native build flow, so please consult a plugin's README to see if this is necessary. In a module project, this will regenerate the module schema.

cfn generate

Command: submit

To register a resource provider, module, or hook in your account, use the submit command.

cfn submit
cfn submit --dry-run #prepares schema handler package without submitting for registration
cfn submit --set-default # if successfully registered, set submitted version to be the new default version

Command: package

This is to create a schema handler package without submitting equivalent to cfn submit --dry-run

cfn package

Command: test

To run the contract tests for a resource type, use the test command.

cfn test
cfn test -- -k contract_delete_update # to run a single test
cfn test -- --tb=long # exhaustive, informative traceback formatting
cfn test --enforce-timeout 60  # Read/List handler timeout (Create/Update/Delete handler timeout is twice the Read/List handler timeout)
cfn test --enforce-timeout 60 -- -k contract_delete_update # combine arguments
cfn test --log-group-name cw_log_group --log-role-arn log_delivery_role_arn # Handler logs generated by contract tests will be delivered to the specified cw_log_group using the credentials from log_delivery_role_arn

Note:

  • To use your type configuration in contract tests, you will need to save your type configuration json file in ~/.cfn-cli/typeConfiguration.json or specify the file you would like to use

    • --typeconfig ./myResourceTypeConfig.json
    • --typeconfig /test/myresource/config1.json
    • --typeconfig C:\MyResource\typeconf.json
  • To use propertyTransform in schema, you will need to install PYJQ. This feature will not be available to use with contract tests on Windows OS

Install PYJQ for Linux system

yum install autoconf automake libtool
pip install pyjq

Install PYJQ for macOS system

brew install autoconf automake libtool
brew install jq
pip install pyjq

Install PYJQ for Ubuntu system

pip install pyjq

Command: validate

To validate the schema, use the validate command.

This command is automatically run whenever one attempts to submit a resource, module, or hook. Errors will prevent you from submitting your resource/module. Module fragments will additionally be validated via cfn-lint (but resulting warnings will not cause this step to fail).

cfn validate

Command: build-image

To build an image for a resource type. This image provides a minimalistic execution environment for the resource handler that does not depend on AWS Lambda in anyway. This image can be used during cfn invoke and cfn test instead of using sam cli.

cfn build-image
cfn build-image --image-name my-handler --executable target/myjar.jar

The resulting image can be run in a container by executing the following command:

docker run IMAGE_NAME HANDLER_ENTRYPOINT PAYLOAD
docker run my-test-resource com.my.test.resource.ExecutableHandlerWrapper PAYLOAD_JSON # Example for a java based-project

Development

For developing, it's strongly suggested to install the development dependencies inside a virtual environment. (This isn't required if you just want to use this tool.)

python3 -m venv env
source env/bin/activate
pip install -e . -r requirements.txt
pre-commit install

If you're creating a resource or hook type, you will also need to install a language plugin, such as the Java language plugin, also via pip install. For example, assuming the plugin is checked out in the same parent directory as this repository:

pip install -e ../cloudformation-cli-java-plugin
# run all hooks on all files, mirrors what the CI runs
pre-commit run --all-files
# run unit tests only. can also be used for other hooks, e.g. black, flake8, pylint-local
pre-commit run pytest-local

If you want to generate an HTML coverage report afterwards, run coverage html. The report is output to htmlcov/index.html.

Plugin system

New language plugins can be independently developed. As long as they declare the appropriate entry point and are installed in the same environment, they can even be completely separate codebases. For example, a plugin for Groovy might have the following entry point:

entry_points={
    "rpdk.v1.languages": ["groovy = rpdk.groovy:GroovyLanguagePlugin"],
},

Plugins must provide the same interface as LanguagePlugin (in plugin_base.py). And they may inherit from LanguagePlugin for the helper methods - but this is not necessary. As long as the class has the same methods, it will work as a plugin.

Supported plugins

Resource Types Supported Plugins

Language Status Github PyPI
Java Available cloudformation-cli-java-plugin cloudformation-cli-java-plugin
Go Available cloudformation-cli-go-plugin cloudformation-cli-go-plugin
Python Available cloudformation-cli-python-plugin cloudformation-cli-python-plugin
TypeScript Available cloudformation-cli-typescript-plugin cloudformation-cli-typescript-plugin

Hook Types Supported Plugins

Language Status Github PyPI
Java Available cloudformation-cli-java-plugin cloudformation-cli-java-plugin
Python Available cloudformation-cli-python-plugin cloudformation-cli-python-plugin

License

This library is licensed under the Apache 2.0 License.

Community

Join us on Discord! Connect & interact with CloudFormation developers & experts, find channels to discuss and get help for our CLI, cfn-lint, CloudFormation registry, StackSets, Guard and more:

Join our Discord

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

cloudformation-cli-0.2.34.tar.gz (102.4 kB view details)

Uploaded Source

Built Distribution

cloudformation_cli-0.2.34-py3-none-any.whl (134.2 kB view details)

Uploaded Python 3

File details

Details for the file cloudformation-cli-0.2.34.tar.gz.

File metadata

  • Download URL: cloudformation-cli-0.2.34.tar.gz
  • Upload date:
  • Size: 102.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for cloudformation-cli-0.2.34.tar.gz
Algorithm Hash digest
SHA256 ef64731ef554f37c9b91a48b3ba605a4b9a77d7c63297cbe54492d1e42fcf164
MD5 e361433eb4c49ea2933a704510d21d11
BLAKE2b-256 82d7c057c62f3cdd8d1baee6ed239ea8f97f738cbab3c5ef46144a7888e679e3

See more details on using hashes here.

File details

Details for the file cloudformation_cli-0.2.34-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudformation_cli-0.2.34-py3-none-any.whl
Algorithm Hash digest
SHA256 e4354f07876c28c5bf171f859f34726249d73a56725ae3c9180ff527cd9e300e
MD5 d0b18f30d83f932df35b708e4220f39e
BLAKE2b-256 cf38abfebcfd62babf064eb56f360667ff0e95444e1e7134d81e266be9c3e7ee

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