Skip to content

add BUCKET_MARKER_LOCAL config #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2023
Merged

add BUCKET_MARKER_LOCAL config #215

merged 1 commit into from
Mar 30, 2023

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Mar 28, 2023

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.

@bentsku bentsku requested a review from whummer March 28, 2023 18:22
Copy link
Member

@whummer whummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, kudos for proactively fixing this @bentsku ! 🚀

@Edwin-Luijten
Copy link

Edwin-Luijten commented Mar 29, 2023

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

  • Request for resource type "AWS::Lambda::Version" in region eu-central-1: publish_version {'FunctionName': 'api-local-api', 'CodeSha256': 'qjSNWDUILUdXq+pUZTZOla7xmgKfd3JDdy6d4i71rlk='}
  • Error calling <bound method ClientCreator._create_api_method.._api_call of <botocore.client.Lambda object at 0x7f041d9769e0>> with params: {'FunctionName': 'api-local-api', 'CodeSha256': 'qjSNWDUILUdXq+pUZTZOla7xmgKfd3JDdy6d4i71rlk='} for resource: {'Type': 'AWS::Lambda::Version', 'DeletionPolicy': 'Retain', 'LogicalResourceId': 'ApiLambdaVersionkZVO2xaDQzLtA17U1kQTRh12fjGFr8OyPVjNZvTzds', 'Properties': {'FunctionName': api-local-api', 'CodeSha256': 'qjSNWDUILUdXq+pUZTZOla7xmgKfd3JDdy6d4i71rlk='}, 'PhysicalResourceId': None, 'state': {}}

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
Copy link
Contributor Author

bentsku commented Mar 29, 2023

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
Copy link

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

@bentsku
Copy link
Contributor Author

bentsku commented Mar 29, 2023

@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
Copy link

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

@dfangl
Copy link
Member

dfangl commented Mar 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants