sam package
The AWS Serverless Application Model Command Line Interface (AWS SAM CLI) 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.
Note
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
<arguments>
<options>
Arguments
- Resource ID
-
The ID of the Lambda function to package.
This argument is optional. If your application contains a single Lambda function, the AWS SAM CLI will package it. If your application contains multiple functions, provide the ID of the function to package a single function.
Valid values: The resource's logical ID or resource ARN.
Options
--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.
--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.
--debug
-
Turns on debug logging to print debug message generated by the AWS SAM CLI and display timestamps.
--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.
--help
-
Shows this message and exits.
--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.
--metadata
-
(Optional) A map of metadata to attach to all artifacts that are referenced in your template.
--no-progressbar
-
Do not display a progress bar when uploading artifacts to Amazon S3.
--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.
--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.
--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. --s3-bucket
TEXT
-
The name of the Amazon S3 bucket where this command uploads your artifact. If your artifact 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. --save-params
-
Save the parameters that you provide at the command line to the AWS SAM configuration file.
--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
. --template-file, --template, -t
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.
--use-json
-
Output JSON for the AWS CloudFormation template. YAML is used by default.
Example
The following example creates and packages artifacts for a Lambda function and CodeDeploy applications. Artifacts are uploaded to an Amazon S3 bucket. The output of the command is a new file called package.yml
.
$
sam package \ --template-file template.yml \ --output-template-file package.yml \ --s3-bucket
amzn-s3-demo-bucket