sam package
Packages an AWS SAM application. This command creates a .zip
file of your code and
dependencies, and uploads the file to Amazon Simple Storage Service (Amazon S3). AWS SAM enables encryption for all files
stored in Amazon S3. It then returns a copy of your AWS SAM template, replacing references to local
artifacts with the Amazon S3 location where the command uploaded the artifacts.
By default when you use this command, the AWS SAM CLI assumes that your current working
directory is your project's root directory. The AWS SAM CLI first tries to locate a template file
built using the sam build command, located in the
.aws-sam
subfolder, and named template.yaml
. Next, the AWS SAM CLI tries
to locate a template file named template.yaml
or template.yml
in the
current working directory. If you specify the --template
option, AWS SAM CLI's default
behavior is overridden, and will package just that AWS SAM template and the local resources it
points to.
sam deploy now implicitly performs the functionality
of sam package
. You can use the sam deploy command directly to package and deploy
your application.
Usage:
sam package [OPTIONS] [ARGS]...
Options:
Option | Description |
---|---|
-t, --template-file, --template PATH |
The path and file name where your AWS SAM template is located. Note: If you specify this option, AWS SAM packages only the template and the local resources that it points to. |
--s3-bucket TEXT |
The name of the Amazon S3 bucket where this command uploads your AWS CloudFormation template. If your
template is larger than 51,200 bytes, then either the --s3-bucket or the
--resolve-s3 option is required. If you specify both the
--s3-bucket and --resolve-s3 options, then an error will
result. |
--s3-prefix TEXT |
Prefix added to the artifacts name that are uploaded to the Amazon S3 bucket. The prefix name
is a path name (folder name) for the Amazon S3 bucket. This only applies for functions declared
with Zip package type. |
--image-repository TEXT |
The URI of the Amazon Elastic Container Registry (Amazon ECR) repository where this command uploads your function's
image. Required for functions declared with the Image package type. |
--kms-key-id TEXT |
The ID of an AWS Key Management Service (AWS KMS) key used to encrypt artifacts that are at rest in the Amazon S3 bucket. If this option is not specified, then AWS SAM uses Amazon S3-managed encryption keys. |
--signing-profiles LIST |
(Optional) The list of signing profiles to sign your deployment packages with. This
parameter takes a list of key-value pairs, where the key is the name of the function or layer
to sign, and the value is the signing profile, with an optional profile owner delimited with
: . For example, FunctionNameToSign=SigningProfileName1
LayerNameToSign=SigningProfileName2:SigningProfileOwner . |
--output-template-file PATH |
The path to the file where the command writes the packaged template. If you don't specify a path, the command writes the template to the standard output. |
--use-json |
Output JSON for the AWS CloudFormation template. YAML is used by default. |
--resolve-s3 |
Automatically create an Amazon S3 bucket to use for packaging. If you specify both the
--s3-bucket and --resolve-s3 options, then an error will
result. |
--force-upload |
Override existing files in the Amazon S3 bucket. Specify this flag to upload artifacts even if they match existing artifacts in the Amazon S3 bucket. |
--metadata |
(Optional) A map of metadata to attach to all artifacts that are referenced in your template. |
--profile TEXT |
The specific profile from your credential file that gets AWS credentials. |
--region TEXT |
The AWS Region to deploy to. For example, us-east-1. |
--config-file PATH |
The path and file name of the configuration file containing default parameter values to use. The default value is "samconfig.toml" in the root of the project directory. For more information about configuration files, see AWS SAM CLI configuration file. |
--config-env TEXT |
The environment name specifying the default parameter values in the configuration file to use. The default value is "default". For more information about configuration files, see AWS SAM CLI configuration file. |
--no-progressbar |
Do not display a progress bar when uploading artifacts to Amazon S3. |
--debug |
Turns on debug logging to print debug message generated by the AWS SAM CLI and display timestamps. |
--help |
Shows this message and exits. |
If the AWS SAM template contains a Metadata
section for ServerlessRepo, and the
LicenseUrl
or ReadmeUrl
properties contain references to local files,
you must update AWS CLI to version 1.16.77 or later. For more information about the
Metadata
section of AWS SAM templates and publishing applications with AWS SAM CLI, see
Publishing serverless
applications using the AWS SAM CLI.