aws-cloudformation/aws-cloudformation-samples

Example of module registration

xiaket opened this issue · 6 comments

Hi AWS,

Like many others, we are really interested in this project and we would like to dig a bit deeper to understand how can we upload a module via code, not using the cloudformation cli. The use case is as long as we can register a module via code, we can do that in a lambda function so we can better manage all the modules via code.

Do we have a minimal example that we are using either awscli or boto3 to register the modules? Thanks!

Hi Xiaket,

Modules can be registered through the CloudFormation API using the register-type CLI (or API via boto). The cfn submit command does the following:

  1. Package your module as a zip file. Your zip file contains:
    a. The schema file in the root.
    b. The .rpdk-config file in the root.
    c. Your module fragment in a directory named fragments.

Example file tree:

.
├── .rpdk-config
├── fragments
│   └── s3.json
└── schema.json

  1. Upload your zip package to S3.
    a. Be sure to provide the appropriate IAM permissions to allow the CloudFormation service to ListBucket and GetObject. See this template for guidance on the bucket permissions needed

  2. Use the register-type command to register your module:

aws cloudformation register-type
--type-name MyCompany::S3::Bucket::MODULE
--schema-handler-package s3://bucket_name/mycompany-s3-bucket-module-2020-12-02T21-46-50.zip
--type MODULE

  1. Use the describe-type-registration command to check the status of registration:

aws cloudformation describe-type-registration
--registration-token put_your_token_here

Thanks @craigataws for your walk through on the process! I appreciate that!

According to the boto3 documentation for 1.16.28, the register_type api will only accept RESOURCE as type for now. I will verify this process later today.

Happy to help. I just looked at the docs, looks like type accepts MODULE? (snippet below). Let me know if you run into any issues

response = client.register_type(
    Type='RESOURCE'|'MODULE',
    TypeName='string',
    SchemaHandlerPackage='string',
    LoggingConfig={
        'LogRoleArn': 'string',
        'LogGroupName': 'string'
    },
    ExecutionRoleArn='string',
    ClientRequestToken='string'
)

In the parameters section under Type, doc said Currently, the only valid value is RESOURCE . Even the latest boto3 version 1.16.29 released 3 hours ago have this note.

Although I suspect this note is out of date.

I see the issue now - I beleive boto pulls from our API docs. I've submitted a ticket to the docs team to address. I've also submitted an issue for the DeregisterType doc as well. Keeping this open to track.

Thanks for your help @craigataws , we've verified that this works. Also we found this page that will allow us to define a module via cloudformation. Once again, we appreciate your help on this!