Skip to content

Commit

Permalink
Add support for Modules (#634)
Browse files Browse the repository at this point in the history
This release adds support for creating Modules using the CFN CLI
 * Initialize a Module project with `cfn init --artifact-type MODULE --type-name <type-name>`
 * For example: `cfn init --artifact-type MODULE --type-name My::Test::Example::MODULE`
 * Using `cfn init` without parameters will now first ask if you want to create a resource or a module. If you choose to create a module, it will create an example module template under fragments/sample.json which you can use as a starting point to make your changes.
 * Use `cfn validate` to validate your module before submitting
 * Use `cfn submit` to register your module, making it available for use by CloudFormation in your AWS account
 * Find detailed documentation about creating Modules [here](docs.aws.amazon.com/cloudformation-cli/latest/userguide/modules.html)

 Backwards-incompatible changes:
  * To use `cfn init` without going into interactive mode, you now need to specify the artifact type. So, to initialize a resource project, you would use
    * `cfn init --artifact-type RESOURCE --type-name <type-name>`
    * or for short: `cfn init -a r -t <type-name>`
  • Loading branch information
MalikAtalla-AWS authored Nov 24, 2020
1 parent 55c2ad0 commit d33aae9
Show file tree
Hide file tree
Showing 62 changed files with 2,937 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
build/
build
develop-eggs/
dist/
downloads/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
- flake8-pep3101>=1.2.1
# language_version: python3.6
- id: pretty-format-json
exclude: inputs.json
exclude: "[inputs.json|syntax_error.json]"
args:
- --autofix
- --indent=4
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# AWS CloudFormation CLI

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

## Usage

### Documentation

Primary documentation for the CloudFormation CLI can be found at the [AWS Documentation](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-types.html) site.
Primary documentation for the CloudFormation CLI can be found at the [AWS Documentation](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html) site.

### Installation

This tool can be installed using [pip](https://pypi.org/project/pip/) from the Python Package Index (PyPI). It requires Python 3. The tool requires at least one language plugin. The language plugins are also available on PyPI and as such can be installed all at once:
This tool can be installed using [pip](https://pypi.org/project/pip/) from the Python Package Index (PyPI). It requires Python 3. For resource 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:

```bash
pip install cloudformation-cli cloudformation-cli-java-plugin cloudformation-cli-go-plugin cloudformation-cli-python-plugin
Expand All @@ -28,6 +28,7 @@ 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.

```bash
cfn generate
Expand All @@ -44,7 +45,7 @@ cfn submit --dry-run #prepares schema handler package without submitting for reg

### Command: test

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

```bash
cfn test
Expand All @@ -56,7 +57,7 @@ cfn test --enforce-timeout 60 -- -k contract_delete_update # combine args

### Command: build-image

To build an image. This image provides a minimalistic execution environment for the 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.
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.

```bash
cfn build-image
Expand All @@ -82,7 +83,7 @@ pip install -e . -r requirements.txt
pre-commit install
```

You will also need to install a language plugin, such as [the Java language plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin), also via `pip install`. For example, assuming the plugin is checked out in the same parent directory as this repository:
If you're creating a resource type, you will also need to install a language plugin, such as [the Java language plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin), also via `pip install`. For example, assuming the plugin is checked out in the same parent directory as this repository:

```bash
pip install -e ../cloudformation-cli-java-plugin
Expand Down
24 changes: 24 additions & 0 deletions fragments/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A secure S3 Bucket. The features are Versioning and DeletionPolicy.",
"Parameters": {
"BucketName": {
"Description": "Name for the bucket",
"Type": "String"
}
},
"Resources": {
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": {
"Ref": "BucketName"
},
"VersioningConfiguration": {
"Status": "Enabled"
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/rpdk/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

__version__ = "0.1.14"
__version__ = "0.2.0"

logging.getLogger(__name__).addHandler(logging.NullHandler())
2 changes: 1 addition & 1 deletion src/rpdk/core/contract/resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _call(self, payload):
LOG.debug("=== Handler execution logs ===")
LOG.debug(result)
# pylint: disable=W1401
regex = "__CFN_RESOURCE_START_RESPONSE__([\s\S]*)__CFN_RESOURCE_END_RESPONSE__" # noqa: W605 # pylint: disable=C0301
regex = "__CFN_RESOURCE_START_RESPONSE__([\s\S]*)__CFN_RESOURCE_END_RESPONSE__" # noqa: W605,B950 # pylint: disable=C0301
payload = json.loads(re.search(regex, result).group(1))
else:
result = self._client.invoke(
Expand Down
24 changes: 24 additions & 0 deletions src/rpdk/core/data/examples/module/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A secure S3 Bucket. The features are Versioning and DeletionPolicy.",
"Parameters": {
"BucketName": {
"Description": "Name for the bucket",
"Type": "String"
}
},
"Resources": {
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": {
"Ref": "BucketName"
},
"VersioningConfiguration": {
"Status": "Enabled"
}
}
}
}
}
Loading

0 comments on commit d33aae9

Please sign in to comment.