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

Cannot deploy selected functions #82

Open
selmeci opened this issue Aug 19, 2020 · 2 comments · Fixed by serverless/serverless#8315
Open

Cannot deploy selected functions #82

selmeci opened this issue Aug 19, 2020 · 2 comments · Fixed by serverless/serverless#8315

Comments

@selmeci
Copy link

selmeci commented Aug 19, 2020

🐛 Bug description

Cannot deploy selected functions from sls configuration.

🤔 Expected Behavior

Deploying selected functions

👟 Steps to reproduce

slss --stage=stage --region=eu-west-1 deploy --config=some-config.yaml --function=echo

result into error:

Error: ENOENT: no such file or directory, open 'C:\Users\abc\IdeaProjects\sls-project\C:\Users\abc\IdeaProjects\sls-project\target\lambda\release\echo.zip'

There is duplicated file path.

🌍 Your environment

Operating System: win32
Node Version: 12.18.3
Framework Version: 1.78.1
Plugin Version: 3.7.0
SDK Version: 2.3.1
Components Version: 2.34.3

rust-plugin version: 0.3.8

@rib
Copy link

rib commented Oct 1, 2020

I hit this same issue and wrote up a bunch of details as I chased down what was going on over here: serverless/serverless#6752

It looks like there are two ways to potentially fix this - though it might be best to apply a fix here and in serverless since the issue in serverless might cause other similar failures in any case where a user or plugin sets an absolute path for a package artifact.

In serverless-rust/index.js there is this code:

      //
      // The AWS "provided" lambda runtime requires executables to be named
      // "bootstrap" -- https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
      //
      // To avoid artifact naming conflicts when we potentially have more than one function
      // we leverage the ability to declare a package artifact directly
      // see https://serverless.com/framework/docs/providers/aws/guide/packaging/
      // for more information
      const artifactPath = path.join(
        this.srcPath,
        `target/lambda/${"dev" === profile ? "debug" : "release"}`,
        `${binary}.zip`
      );
      console.log("AP: " + artifactPath); // DEBUG
      func.package = func.package || {};
      func.package.artifact = artifactPath;

which I think would ideally set a relative artifactPath instead of an absolute path. The basic issue here is that serverless is later on assuming a relative artifact path and joins it to the service path.

Specifically in serverless, in lib/plugins/package/lib/packageService.js there is this code:

packageFunction(functionName) {
    const functionObject = this.serverless.service.getFunction(functionName);
    const funcPackageConfig = functionObject.package || {};

    // use the artifact in function config if provided
    if (funcPackageConfig.artifact) {
      const filePath = path.join(this.serverless.config.servicePath, funcPackageConfig.artifact);
      console.log("filePath: join(" + this.serverless.config.servicePath + "," + funcPackageConfig.artifact + ")" ); // DEBUG
      functionObject.package.artifact = filePath;
      return BbPromise.resolve(filePath);
    }

which joins the above absolute path with the servicePath leading to this issue.

I found that this modification fixed the issue for me:

    // use the artifact in function config if provided
    if (funcPackageConfig.artifact) {
      const filePath = path.isAbsolute(funcPackageConfig.artifact) ?
            funcPackageConfig.artifact :
            path.join(this.serverless.config.servicePath, funcPackageConfig.artifact);
      console.log("filePath: join(" + this.serverless.config.servicePath + "," + funcPackageConfig.artifact + ")" );
      functionObject.package.artifact = filePath;
      return BbPromise.resolve(filePath);
    }

@rib
Copy link

rib commented Oct 1, 2020

From the pov of the serverless framework it sounds like they see this as a serverless-rust plugin bug and it wasn't intended to be possible to set absolute artifact paths. (serverless/serverless#8315 (review))

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 a pull request may close this issue.

2 participants