Package: cloudformation-cli
AWS CloudFormation CLIThe CloudFormation CLI (cfn) allows you to author your own resource providers, hooks, and modules that can be used by CloudFormation.UsageDocumentationPrimary documentation for the CloudFormation CLI can be found at theAWS Documentationsite.InstallationThis tool can be installed usingpipfrom 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:pipinstallcloudformation-clicloudformation-cli-java-plugincloudformation-cli-go-plugincloudformation-cli-python-plugincloudformation-cli-typescript-pluginCommand: initTo create a project in the current directory, use theinitcommand. A wizard will guide you through the creation.cfninitCommand: generateTo refresh auto-generated code, use thegeneratecommand. 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.cfngenerateCommand: submitTo register a resource provider, module, or hook in your account, use thesubmitcommand.cfnsubmit
cfnsubmit--dry-run#prepares schema handler package without submitting for registrationcfnsubmit--set-default# if successfully registered, set submitted version to be the new default versionCommand: packageThis is to create a schema handler package without submitting equivalent tocfn submit --dry-runcfnpackageCommand: testTo run the contract tests for a resource type, use thetestcommand.cfntestcfntest---kcontract_delete_update# to run a single testcfntest----tb=long# exhaustive, informative traceback formattingcfntest--enforce-timeout60# Read/List handler timeout (Create/Update/Delete handler timeout is twice the Read/List handler timeout)cfntest--enforce-timeout60---kcontract_delete_update# combine argumentscfntest--log-group-namecw_log_group--log-role-arnlog_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_arnNote:To use your type configuration in contract tests, you will need to save your type configuration json file in~/.cfn-cli/typeConfiguration.jsonor specify the file you would like to use--typeconfig ./myResourceTypeConfig.json--typeconfig /test/myresource/config1.json--typeconfig C:\MyResource\typeconf.jsonTo usepropertyTransformin schema, you will need to installPYJQ. This feature will not be available to use with contract tests on Windows OSInstall PYJQ for Linux systemyuminstallautoconfautomakelibtool
pipinstallpyjqInstall PYJQ for macOS systembrewinstallautoconfautomakelibtool
brewinstalljq
pipinstallpyjqInstall PYJQ for Ubuntu systempipinstallpyjqCommand: validateTo validate the schema, use thevalidatecommand.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 viacfn-lint(but resulting warnings will not cause this step to fail).cfnvalidateCommand: build-imageTo 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.cfnbuild-image
cfnbuild-image--image-namemy-handler--executabletarget/myjar.jarThe 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-projectDevelopmentFor 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-mvenvenvsourceenv/bin/activate
pipinstall-e.-rrequirements.txt
pre-commitinstallIf you're creating a resource or hook type, you will also need to install a language plugin, such asthe Java language plugin, also viapip install. For example, assuming the plugin is checked out in the same parent directory as this repository:pipinstall-e../cloudformation-cli-java-plugin# run all hooks on all files, mirrors what the CI runspre-commitrun--all-files# run unit tests only. can also be used for other hooks, e.g. black, flake8, pylint-localpre-commitrunpytest-localIf you want to generate an HTML coverage report afterwards, runcoverage html. The report is output tohtmlcov/index.html.Plugin systemNew 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 asLanguagePlugin(inplugin_base.py). And they may inherit fromLanguagePluginfor the helper methods - but this is not necessary. As long as the class has the same methods, it will work as a plugin.Supported pluginsResource Types Supported PluginsLanguageStatusGithubPyPIJavaAvailablecloudformation-cli-java-plugincloudformation-cli-java-pluginGoAvailablecloudformation-cli-go-plugincloudformation-cli-go-pluginPythonAvailablecloudformation-cli-python-plugincloudformation-cli-python-pluginTypeScriptAvailablecloudformation-cli-typescript-plugincloudformation-cli-typescript-pluginHook Types Supported PluginsLanguageStatusGithubPyPIJavaAvailablecloudformation-cli-java-plugincloudformation-cli-java-pluginPythonAvailablecloudformation-cli-python-plugincloudformation-cli-python-pluginLicenseThis library is licensed under the Apache 2.0 License.CommunityJoin 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: