skip to Main Content

After I run sam build for my application, I add a file (which needs to change on every deployment) to a lambda layer before running sam deploy.

I can confirm that the file is created correctly in the right place, but if that’s the only change that happened to the layer, when I run sam deploy the new file is not detected and the layer is not uploaded at all (because SAM thinks there is no difference).

I don’t know how SAM checks for differences, because I would expect a whole new file (or a modified one) in the build folder for a layer to be detected as a change.

I’m aware of the --force-upload flag, but I’m under the impression that would force everything to be reuploaded. Given that the application is large, I don’t want to do that just to update a single file in a single layer.

Is there a way to force-upload just the layer? Is there something I should be doing when adding arbitrary files to the build so that SAM can detect them?

2

Answers


  1. Chosen as BEST ANSWER

    It's more of a workaround than a solution, since this doesn't explain why the problem occurs, but I managed to make it work by adding the file to the layer's code before the build process, so that sam build then included the file by itself.
    This is a bit dirtier because it's a file I don't need to commit to git and that is generated anew on every deployment, so I also needed to add it to .gitignore.

    My guess is that the cache is calculated by sam build and then trusted by sam deploy, so if the build files change in the meantime they are not detected. If that's the case, it's a bit stupid, if you ask me, but it's just a hypothesis.

    TL;DR: include any extra files before running sam build, putting them in the code itself.


  2. You should use sam package to upload the .zip to S3.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search