AWS SAM CLI configuration file (original) (raw)

The AWS Serverless Application Model Command Line Interface (AWS SAM CLI) supports a project-level configuration file that you can use to configure AWS SAM CLI command parameter values.

For documentation on creating and using configuration files, see Configuring the AWS SAM CLI.

Topics

Default configuration file settings

AWS SAM uses the following default configuration file settings:

The following is an example project structure that includes the default configuration file name and location:

sam-app ├── README.md ├── init.py ├── events ├── hello_world ├── samconfig.toml ├── template.yaml └── tests

The following is an example samconfig.toml file:

... version = 0.1

[default] [default.global] [default.global.parameters] stack_name = "sam-app"

[default.build.parameters] cached = true parallel = true

[default.deploy.parameters] capabilities = "CAPABILITY_IAM" confirm_changeset = true resolve_s3 = true

[default.sync.parameters] watch = true

[default.local_start_api.parameters] warm_containers = "EAGER"

[prod] [prod.sync] [prod.sync.parameters] watch = false

Supported configuration file formats

TOML and [YAML|YML] formats are supported. See the following basic syntax:

TOML

version = 0.1
[environment]
[environment.command]
[environment.command.parameters]
option = parameter value

YAML

version: 0.1
environment:
  command:
    parameters:
      option: parameter value

Specify a configuration file

By default, the AWS SAM CLI looks for a configuration file in the following order:

  1. Custom configuration file – If you use the --config-file option to specify a file name and location, the AWS SAM CLI looks for this file first.
  2. Default samconfig.toml file – This is the default configuration file name and format, located at the root of your project. If you don’t specify a custom configuration file, the AWS SAM CLI looks for this file next.
  3. samconfig.[yaml|yml] file – If the samconfig.toml does not exist at the root of your project, the AWS SAM CLI looks for this file.

The following is an example of specifying a custom configuration file using the --config-file option:

$ sam deploy --config-file myconfig.yaml
Note

The --config-file parameter must be relative to the location of the AWS SAM template file because the AWS SAM CLI needs to determine the context in which the configuration is applied. The samconfig.toml file manages configuration settings for your version of the AWS SAM CLI, and the CLI looks for the samconfig.toml file (or the overriden config file parameter) in the relative the folder of the template.yaml file.

Configuration file basics

Environment

An environment is a named identifier that contains a unique set of configuration settings. You can have multiple environments in a single AWS SAM application.

The default environment name is default.

Use the AWS SAM CLI --config-env option to specify the environment to use.

Command

The command is the AWS SAM CLI command to specify parameter values for.

To specify parameter values for all commands, use the global identifier.

When referencing an AWS SAM CLI command, replace spaces ( ) and hyphens () with underscores (_). See the following examples:

Parameters

Parameters are specified as key-value pairs.

When specifying keys, use the long-form command option name and replace hyphens () with underscores (_). The following are examples:

Parameter value rules

TOML

YAML

$ sam deploy --tags "foo=bar hello=world"  
default:  
  deploy:  
    parameters:  
      tags: foo=bar hello=world  
$ sam remote invoke --parameter "InvocationType=Event" --parameter "LogType=None"  
default:  
  remote_invoke:  
    parameters:  
        parameter:  
        - InvocationType=Event  
        - LogType=None  

Configuration precedence

When configuring values, the following precedence takes place:

default:  
  global:  
    parameters:  
      stack_name: common-stack  
  deploy:  
    parameters:  
      stack_name: my-app-stack  

Creating and modifying configuration files

Creating configuration files

When you create an application using sam init, a default samconfig.toml file is created. You can also manually create your configuration file.

Modifying configuration files

You can manually modify your configuration files. Also, during any AWS SAM CLI interactive flow, configured values will be displayed in brackets ([ ]). If you modify these values, the AWS SAM CLI will update your configuration file.

The following is an example interactive flow using the sam deploy --guided command:

$ sam deploy --guided

Configuring SAM deploy
======================

    Looking for config file [samconfig.toml] :  Found
    Reading default arguments  :  Success

    Setting default arguments for 'sam deploy'
    =========================================
    Stack Name [sam-app]: ENTER
    AWS Region [us-west-2]: ENTER
    #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
    Confirm changes before deploy [Y/n]: n
    #SAM needs permission to be able to create roles to connect to the resources in your template
    Allow SAM CLI IAM role creation [Y/n]: ENTER
    #Preserves the state of previously provisioned resources when an operation fails
    Disable rollback [y/N]: ENTER
    HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: y
    Save arguments to configuration file [Y/n]: ENTER
    SAM configuration file [samconfig.toml]: ENTER
    SAM configuration environment [default]: ENTER

When modifying your configuration file, the AWS SAM CLI handles global values as follows: