localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
511 stars 82 forks source link

add BUCKET_MARKER_LOCAL config #215

Closed bentsku closed 1 year ago

bentsku commented 1 year ago

Adding the BUCKET_MARKER_LOCAL, same as LocalStack configuration, please feel free to correct the name, I don't have much inspiration! For now, the default is still __local__ but we can now set it to hot-reload with this environment variable.

Edwin-Luijten commented 1 year ago

I tested this with a localstack docker setup an I encounter this error when setting the environment variable value to hot-reload:

An error occurred (InvalidParameterValueException) when calling the PublishVersion operation: CodeSHA256 (qjSNWDUILUdXq+pUZTZOla7xmgKfd3JDdy6d4i71rlk=) is different from current CodeSHA256 in $LATEST (hot-reloading-hash-not-available). Please try again with the CodeSHA256 in $LATEST.

This is my plugin config:

custom:
  stage: local
  webpack: ${file(./serverless.yml):custom.webpack}
  localstack:
    debug: true
    edgePort: 4566
    autostart: false
    stages: [ local ]
    lambda:
      mountCode: true

Added the BUCKET_MARKER_LOCAL to my environment variables in my docker-compose file:

...
    environment:
      - EAGER_SERVICE_LOADING=1
      - LS_LOG=debug
      - PERSISTENCE=1
      - BUCKET_MARKER_LOCAL=hot-reload
      ...

Disabling versioning seems to work:

provider:
  versionFunctions: false
  ...
bentsku commented 1 year ago

Hello @Edwin-Luijten,

For now, this configuration is not available yet, but once this PR is merged and a new version is published, you should be able to use BUCKET_MARKET_LOCAL=hot-reload when deploying serverless. You would need to run it this way as well for now: BUCKET_MARKET_LOCAL=hot-reload sls deploy ... so that when creating your lambda functions, the localstack-serverless plugin would also be aware of this configuration, and this should fix your issue.

Thanks for the pointer about versioning!

Tagging @joe4dev here as well, feel free to correct me if I'm wrong with this.

Edwin-Luijten commented 1 year ago

@bentsku Yup, I understand. I applied that patch locally to test it out =D.

bentsku commented 1 year ago

@bentsku Yup, I understand. I applied that patch locally to test it out =D.

@Edwin-Luijten oh okay, sorry for the misunderstanding! And you still had that issue you reported?

Edwin-Luijten commented 1 year ago

Indeed. That issue went away when I disabled function versioning.

dfangl commented 1 year ago

Seems like an issue with the LS side validation of hashes, we should not validate hot-reloading hashes. Will come up with a fix! Of course, due to hot reloading, even published versions will be hot reloading, so you cannot version your code like this (LS itself does not have access to the code, it is directly mounted into the lambda container), but this should be expected behavior.