Skip to content

With Runtime: provided, sam build copies source to a temp dir, breaking builds that use relative paths #2077

@JackKelly-Bellroy

Description

@JackKelly-Bellroy

Description:

When sam build tries to build a runtime: provided Function, if the build system uses relative paths then it will fail when copied to the temporary directory sam build uses.

Steps to reproduce the issue:

Given a repository containing multiple Haskell libraries and services, structured roughly as follows:

/
├── lib
│   ├── lib1
│   │   └── stack.yaml
│   └── lib2
│       └── stack.yaml
└── service
    ├── service1
    │   ├── Makefile
    │   ├── samconfig.toml
    │   ├── stack.yaml
    │   └── template.yaml
    └── service2
        ├── Makefile
        ├── samconfig.toml
        ├── stack.yaml
        └── template.yaml

Each service under /service is a separate CloudFormation stack, so I want to run sam build in e.g. /service/service1. The build system for the service (currently Stack, but not relevant) refers to its dependent libraries using relative paths, saying things like "use ../../lib/library1".

Observed result:

When sam build is run inside service/service1 (say), sam copies the service1 subdirectory to a temporary location and invokes make. make then invokes stack, which fails because the dependent libraries are not present at SOME_TEMP_DIR/../../lib/library1 etc.

Expected result:

I build my code successfully.

Remarks:

As a workaround, I have been able to find my way home with this snippet, but it feels dirty:

REAL_SRC := $(shell echo "$(ARTIFACTS_DIR)" | sed 's@/.aws-sam.*@@')

I am not sure what the best fix looks like. sam's behaviour is by design, so perhaps the answer is to expose (via environment variable or similar) the repository root location and/or the original location of the source code?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions