Aws-sam-cli: sam cli is not syncing code changes automatically

Created on 8 Jan 2019  路  2Comments  路  Source: aws/aws-sam-cli

Description

When I run sam cli locally my code changes are not picked up automatically and every time I have to run sam build after every code change.

Steps to reproduce

  1. From the projects main directory run:

    sam build

  2. Then execute:

    sam local start-api

  3. This will load below directory
    ~/image-resize-lambda/.aws-sam/build/
    But since my main project directory is ~/image-resize-lambda any code changes here are not loaded into the docker container

Expected result

Any code changes in the parent directory should be readily available in the docker container

  1. OSX
  2. SAM CLI, version 0.10.0

SAM template:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
    SAM Template for image resize function

Globals:
    Function:
        Timeout: 3
    Api:
      BinaryMediaTypes:
        - image~1gif
        - image~1png
        - image~1jpeg


Resources:
    Imageresize:
        Type: AWS::Serverless::Function 
        Properties:
            CodeUri: ./
            Handler: index.handler
            Runtime: nodejs8.10

            Events:
              Images:
                Type: Api 
                Properties:
                  Path: /images
                  Method: get

Most helpful comment

@publitas-revolution Thank you for the issue. I have seen this a couple times now, so I created an explicit issue for how we are looking to solve this problem: https://github.com/awslabs/aws-sam-cli/issues/921

In that issue, I provided a 'workaround' which can allow you to do the following:

  • in Terminal A: sam build
  • in Terminal B: sam local start-api
  • in Terminal A: sam build whenever you have code changes.

This will allow you to keep the api up and build when your code changes. This only works as long as the CodeUri doesn't change or new functions/routes are added. I know this workaround doesn't solve the issue but gives a slightly better experience.

I am going to close this in favor of the more specific one I created that we can use to track the implementation.

All 2 comments

@publitas-revolution Thank you for the issue. I have seen this a couple times now, so I created an explicit issue for how we are looking to solve this problem: https://github.com/awslabs/aws-sam-cli/issues/921

In that issue, I provided a 'workaround' which can allow you to do the following:

  • in Terminal A: sam build
  • in Terminal B: sam local start-api
  • in Terminal A: sam build whenever you have code changes.

This will allow you to keep the api up and build when your code changes. This only works as long as the CodeUri doesn't change or new functions/routes are added. I know this workaround doesn't solve the issue but gives a slightly better experience.

I am going to close this in favor of the more specific one I created that we can use to track the implementation.

Just for everyone who ends up at this issue, here is one potential workaround: https://github.com/awslabs/aws-sam-cli/issues/1921#issuecomment-636274872

Was this page helpful?
0 / 5 - 0 ratings

Related issues

red8888 picture red8888  路  3Comments

GerbenRampaart picture GerbenRampaart  路  3Comments

cmccoypdx picture cmccoypdx  路  3Comments

terlar picture terlar  路  3Comments

cvuijst picture cvuijst  路  3Comments