fix internal Serverless custom resources S3 path addressing#209
Merged
fix internal Serverless custom resources S3 path addressing#209
Conversation
whummer
approved these changes
Feb 10, 2023
Member
whummer
left a comment
There was a problem hiding this comment.
Awesome set of changes, very clean and nice solution with the package:compileEvents hook and overwriting the zip archive. 🚀
Over time, we may be able to fix this in the Lambda runtime itself (DNS project, transparent endpoint injection). But this is a great workaround for now.
For the record: Interestingly, I wasn't able to replicate the error on my side (on MacOS). Tried different combinations of host/Docker mode, community/ext, and old/new Lambda provider. Didn't seem to be able to replicate the Inaccessible host: drop-bucket.172.17.0.2\' at port undefined error.. In any case, the changes LGTM, and was able to replicate the behavior of the zip packaging of the patched utils.js locally. 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While debugging a support case about
serverless-python-requirements, I stumbled upon an issue regarding Serverless own internal Custom Resources: they would spin up a lambda to update the notification configuration of an existing S3 bucket. However, they would try to access it using virtual host addressing, leading to the lambda failing and the bucket not getting the right configuration. You can reproduce it using this kind of function events:The deployment would not fail, but the S3 bucket would not trigger the lambda.
This PR introduces a mechanism to hook into
package:compileEventswhich is triggered when building resources to manageevents. We're checking for the presence of thecustom-resources.zipfile, which would be created if Serverless was going to package its internal custom-resources to create its lambdas.We then get the
utils.jsfile which is imported by all lambdas, and set the SDK config there to useS3forcePathStyle=true.As there are nothing in the node standard library to unzip file, I had to introduce a new dependency,
adm-zip.Relevant documentation: