aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

CDK followSymlinks not supported #6959

Open vieirai opened 5 months ago

vieirai commented 5 months ago

SAM should support the CDK followSymlinks config option.

Currently SAM is the recommended tool for running CDK applications locally, as such I expect my CDK config to be compatible with SAM, however that is not always the case. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-testing.html

Proposal

The CDK followSymlinks flag should be supported by SAM. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AssetImageCodeProps.html#followsymlinks

Additional Details

The more I think about this, I'm not even sure if this is a SAM issue, or a Cloudformation issue or a CDK issue. Currently CDK seems to be outputting AWS::Lambda::Function resources, which are part of the Cloudformation spec. I guess CDK would have to be extended to output this flag in the Metadata and them SAM would have to implement some logic on top?

hnnasit commented 5 months ago

Hi @vieirai, thanks for opening the issue. I'm trying to understand this more. I tried playing around with an image type lambda function and followSymlinks enum value and observed that on running cdk synth, the symlinks followed are based on the value set for followSymlinks. E.g. Setting it to NEVER and running sam build or sam local invoke does not follow the symlink and it can't find the Dockerfile, whereas setting it to ALWAYS or EXTERNAL allows the symlink to be followed and find the Dockerfile. Could you elaborate on what support are you looking for with the followSymlinks property for sam local commands and maybe provide an example of how it would work?

vieirai commented 5 months ago

Hi @hnnasit , thank you for looking into this. I can confirm it does work as expected.

In short our project was doing:

cdk synth SymlinkStack --no-staging > template.yml
sam build symlink
sam local invoke symlink

And this way it does not resolve the symlink references and we end up with broken files inside the container. Looks like we were trying to be too smart and avoid having to pass the template path, and it ended up causing problems.

I can confirm that if we follow the docs example and do:

cdk synth
sam build -t cdk.out/SymlinkStack.template.json symlink
sam local invoke -t cdk.out/SymlinkStack.template.json symlink

Then it does work.

Not sure if this is worth highlighting in the docs or not, but either way I'm happy for you to resolve this.

mildaniel commented 2 months ago

This issue seems more like a feature request than a bug since there doesn't seem to be anything broken in the integration at this point and the recommendation is to extend the current functionality to support symlinks.