You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of testing your resource, the CloudFormation CLI performs a suite of tests, each written to test a requirement contained in the [resource type handler contract](resource-type-test-contract.md)\. Each handler invocation is expected to follow the general requirements for that handler listed in the contract\. This topic lists tests that explicitly test some of the more specific requirements\.
The CloudFormation CLI performs the following contract tests for `create` handlers\.
8
+
9
+
10
+
| Test | Description |
11
+
| --- | --- |
12
+
|**contract\_create\_create**| Creates a resource, waits for the resource creation to complete, and then creates the resource again with the expectation that the second create operation will fail with the `AlreadyExists` error code\. This test is not run for resources if the primary identifier or any additional identifiers are read\-only\.|
13
+
|**contract\_create\_read**| Creates a resource, waits for the resource creation to complete, and then reads the created resource to ensure that the input to the `create` handler is equal to the output from the `read` handler\. The comparison ignores any read\-only/generated properties in the `read` output, as create input cannot specify these\. It also ignores any write\-only properties in the create input, as these are removed from read output to avoid security issues\.|
14
+
|**contract\_create\_delete**| Creates a resource, waits for the resource creation to complete, and then deletes the created resource\. It also checks if the create input is equal to the create output \(which is then used for delete input\), with the exception of readOnly and writeOnly properties\.|
15
+
|**contract\_create\_list**| Creates a resource, waits for the resource creation to complete, and then lists out the resources with the expectation that the created resource exists in the returned list\.|
The CloudFormation CLI performs the following contract tests for `update` handlers\.
20
+
21
+
22
+
| Test | Description |
23
+
| --- | --- |
24
+
|**contract\_update\_read**| Creates a resource, updates the resource, and then reads the resource to check that the update was made by comparing the read output with the update input\. The comparison excludes read\-only and write\-only properties because they cannot be included in the update input and read output, respectively\.|
25
+
|**contract\_update\_list**| Creates a resource, updates the resource, and then lists the resource to check that the updated resource exists in the returned list\.|
26
+
|**contract\_update\_without\_create**| Updates a resource without creating it first\. The test expects the update operation to fail with the `NotFound` error code\.|
The CloudFormation CLI performs the following contract tests for `delete` handlers\.
31
+
32
+
33
+
| Test | Description |
34
+
| --- | --- |
35
+
|**contract\_delete\_create**| Creates a resource, deletes the resource, and then creates the resource again with the expectation that the deletion was successful and a new resource can be created\. The CloudFormation CLI performs this contract test for resources with create\-only primary identifiers\.|
36
+
|**contract\_delete\_update**| Creates a resource, deletes the resource, and then updates the resource with the expectation that the update operation will fail with the `NotFound` error code\.|
37
+
|**contract\_delete\_read**| Creates a resource, deletes the resource, and then reads the resource with the expectation that the read operation will fail with the `NotFound` error code\.|
38
+
|**contract\_delete\_list**| Creates a resource, deletes the resource, and then lists the resource with the expectation that the returned list does not contain the deleted resource\.|
39
+
|**contract\_delete\_delete**| Creates a resource, deletes the resource, and then deletes the resource again with the expectation that the second delete operation will fail with the `NotFound` error code\.|
# Develop a module using the CFN\-CLI<aname="modules-develop"></a>
2
+
3
+
Follow these basic steps to develop and register a module project\.
4
+
5
+
1. In the CFN\-CLI, use the `[init](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-cli-init.html)` command to create a new project\. The `init` command creates a `fragments` folder containing a sample fragment file named `sample.json`\.
6
+
7
+
Follow the prompts\. Specify that you want to create a **module\(m\)**, and enter the module name\.
8
+
9
+
```
10
+
cfn init
11
+
Initializing new project
12
+
Do you want to develop a new resource(r) or a module(m)?.
13
+
>> m
14
+
What is the name of your module type?
15
+
(<Organization>::<Service>::<Name>::MODULE)
16
+
>> My::Sample::SampleBucket::MODULE
17
+
```
18
+
19
+
1. Include your template fragment in the project\.
20
+
21
+
In the `fragments` folder in the project, you should find a file named `sample.json`\. This is the template fragment file\. Author your template fragment in this file and save\.
22
+
23
+
You can rename this file as necessary\. The folder can only contain a single file\.
24
+
25
+
For more information, see [Creating a module template fragment](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/modules-structure.html#modules-template-fragment)\.
26
+
27
+
1. Use `[validate](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-cli-validate.html)` to validate your project\. Fix any issues reported\.
28
+
29
+
The `validate` command regenerates the module schema, based on the template fragment you included in the `fragments` folder\. The module schema is located in the root folder, and named `schema.json`\.
30
+
31
+
1. Use `[submit](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-cli-submit.html)` to register the module with CloudFormation, in the specified region\. Registering a module makes it available for inclusion in CloudFormation templates\.
32
+
**Note**
33
+
When you register your module using `submit`, CloudFormation re\-generates your module schema based on the template fragment in your project\. You can't specify a schema file directly\. To specify a module schema file when registering a module, use `[RegisterType](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_RegisterType.html)` in the CloudFormation API\.
34
+
35
+
For information on using modules in CloudFormation templates, see [Using modules](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/modules.html) in the *CloudFormation Users Guide*\.
0 commit comments