Skip to content
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

fix: Resolving symlinks when updating relative paths in template #3764

Merged
merged 4 commits into from Mar 29, 2022

Conversation

calabrla
Copy link
Contributor

Which issue(s) does this change fix?

No issue was created.

Why is this change necessary?

Running sam build against a template that is in a symlinked directory results in incorrect relative paths in the generated template. (See additional context below)

How does it address the issue?

This change resolves symlinks in the original_root and new_root before updating relative paths in the generated template at the end of a build.

What side effects does this change have?

None.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Additional Context

Given the project structure:

.
├── .aws-sam
│   └── build
│       ├── LambdaFunction
│       └── template.yaml
├── build -> /some/other/directory/build
│   └── cdk.out
│       └── Application.template.json
└── lib
    └── app.ts

When the project is built via sam build -t build/cdk.out/Application.template.json, in app_builder.py absolute paths are constructed by resolving all symlinks and then made relative as seen here. Before the template is written, the relative file paths are updated to be relative to a new_root, however neither the new_root nor the original_root are resolved to accommodate symlinks. This results in an incorrect code path and sam local invoke fails to mount the source.

@mildaniel
Copy link
Contributor

Hey @calabrla, thanks for the contribution. Can you please add some tests to validate this change and to make sure we don't break it in the future.

@calabrla
Copy link
Contributor Author

Hi @mildaniel I added unit tests for the _resolve_relative_to method that was updated and confirmed that the tests fail without my change. Let me know if you need anything else.

@hawflau hawflau merged commit df49f9f into aws:develop Mar 29, 2022
mndeveci pushed a commit to mndeveci/aws-sam-cli that referenced this pull request Apr 5, 2022
…#3764)

* fix: Resolving symlinks when updating relative paths in template

* adding unit tests

Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>
Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants