Skip to content

Add --package option to cfn submit for pre-built zip submission#1121

Open
cv-dote wants to merge 5 commits intoaws-cloudformation:masterfrom
cv-dote:feat/submit-existing-zip
Open

Add --package option to cfn submit for pre-built zip submission#1121
cv-dote wants to merge 5 commits intoaws-cloudformation:masterfrom
cv-dote:feat/submit-existing-zip

Conversation

@cv-dote
Copy link
Copy Markdown

@cv-dote cv-dote commented May 4, 2026

Issue #, if available: #291

Description of changes:

Summary

Add a --package / -p option to cfn submit that uploads a pre-built schema handler package zip instead of building one from the current project. This enables common workflows such as building once (for example, inside a Docker container) and registering the same artifact across multiple regions, or registering a third-party zip without rebuilding.

Motivation

Today cfn submit tightly couples the packaging step with the upload step: the CLI always builds a zip from the current working directory and then uploads it. There is no way to feed in an already-built zip, so users can't:

  • Build once, register in many regions.
  • Register a vendor-built zip without rebuilding locally.
  • Re-use the zip produced by cfn submit --dry-run.

Changes

Behavior

  • Added --package <path> and -p <path> options to cfn submit.
  • When --package is used, the CLI validates the zip, reads typeName and artifact_type from its .rpdk-config entry, and uploads the zip's bytes as-is.
  • --package cannot be combined with --dry-run, --use-docker, or --no-docker (those flags configure the packaging step that --package skips). The CLI exits with a clear error if the user tries to combine them.
  • The --package path does not read .rpdk-config from the current working directory, so the option works outside a CloudFormation CLI project.
  • Because the zip does not carry a role template, --role-arn or --no-role must be specified together with --package.

When --package is not used, behavior is unchanged: the original packaging workflow runs with the same inputs, outputs, and log messages as before.

Code

Commit Change
Add PackageValidator for pre-built zip submission New src/rpdk/core/package_validator.py module that opens the zip, reads .rpdk-config, resolves artifact_type (with a RESOURCE fallback for legacy packages), asserts required entries, and logs cli-version from .cfn_metadata.json if present. All failures surface as InvalidProjectError.
Add Project.from_package classmethod for pre-built zip submission New classmethod on Project that builds a minimal instance from the validator's output. Sets schema = {} so _upload's automatic-role branch stays inactive; the caller must provide --role-arn or --no-role. No existing methods are modified.
Add --package option to cfn submit New _submit_existing_package helper and a single-branch dispatch in submit(). The flag-combination check runs before any I/O.
Add unit tests for --package submit workflow New tests/test_submit.py covering parser, dispatch, flag conflicts, and end-to-end upload byte identity via a mocked _upload.
Document --package option in submit command Updates to doc_source/resource-type-cli-submit.md (Synopsis, Options, Examples) and a one-line example in README.md.

Testing

  • 19 new unit tests in tests/test_submit.py.
  • 5 new unit tests in tests/test_project.py for Project.from_package.
  • 17 new unit tests in tests/test_package_validator.py covering happy paths (RESOURCE / MODULE / HOOK), all validation error paths (missing path, non-zip, missing .rpdk-config, invalid JSON, unknown artifact_type, missing typeName, missing schema.json), the legacy RESOURCE fallback, and the best-effort metadata log.
  • All pre-existing tests in tests/test_cli.py, tests/test_project.py, tests/test_package_validator.py, tests/test_submit.py, and tests/test_upload.py pass (206 tests).
  • pre-commit (black, isort, flake8, pylint) passes. No new pylint warnings introduced; pylint rating unchanged at 9.98/10.

Example

# Build once.
cd ~/my-project
cfn submit --dry-run    # produces my-project.zip

# Register in multiple regions without rebuilding.
cfn submit --package ./my-project.zip --region us-east-1 --no-role
cfn submit --package ./my-project.zip --region ap-northeast-1 --role-arn arn:aws:iam::123456789012:role/MyExecutionRole

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant