amazon-web-servicesaws-samaws-sam-cli

AWS CLI - sam deploy vs sam sync


What is the difference between AWS sam deploy and sam sync and when should I use which one?


Solution

  • sam deploy

    The sam deploy command simply deploys your serverless application to the cloud. Use it to manually deploy the application.

    sam sync

    The sam sync command provides options to quickly sync local application changes to the AWS Cloud. Use it to automate the deployment as you make changes in your development environment.

    Use sam sync when developing your applications to:

    1. Automatically detect and sync local changes to the AWS Cloud.

    2. Customize what local changes are synced to the AWS Cloud.

    3. Prepare your application in the cloud for testing and validation.

    With sam sync, you can create a rapid development workflow that shortens the time it takes to sync your local changes to the cloud for testing and validation.

    It does the following:

    1. Build your application – This process is similar to using the sam build command.
    2. Deploy your application – The SAM CLI deploys your application to AWS CloudFormation using your default settings. This process is similar to using the sam deploy command.
    3. Watch for local changes – The SAM CLI remains running and watches for local changes to your application. This is what the --watch option provides.
    4. Sync local changes to the AWS Cloud – When you make local changes, the SAM CLI detects and syncs those changes to the AWS Cloud through the quickest method available.

    Note: Since the sam sync command automatically updates your application in the AWS Cloud, it is recommended for development environments only.

    Source: AWS Documentation - Using sam sync