AWS -Still incorrect path when using $CODEBUILD_SRC_DIR
See original GitHub issueMy Situation
I am using AWS CodeBuild and the newest Serverless Framework to build and deploy my Node.js application as a Lambda.
I package everything with severless package --package /PATH/..
and store the artifacts under this path in a S3.
In my deployment step I use the CODEBUILD_SRC_DIR to get the path/location of the current build artifacts which I want to deploy:
sls deploy --stage $env --package $CODEBUILD_SRC_DIR/target/$env -v -r eu-central-1
Problem I get the following error: Error: ENOENT: no such file or directory, open ‘/codebuild/output/src067167590/src/codebuild/output/src067167590/src/target/dev/serverless-state.json’
As you can see there seems to be something wrong with the path which I get back from $CODEBUILD_SRC_DIR . It doubles “/codebuild/output/src067167590” and therefore it cannot find the files.
Strange is when I do echo $CODEBUILD_SRC_DIR
everything seems to be fine. Is it a problem with the command sls deploy
?
My Solution Like the other guys mentioned I rolled also back to serverless 1.38. Then it works.
Is it sill not fixed ?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (5 by maintainers)
Hopefully patch will land next week
For anyone else experiencing this issue, I finally identified the root cause and a simple workaround.
In summary, the “artifact” incorrectly has “$CODEBUILD_SRC_DIR” in the value. Also, the srcxxxxxxxxxx number changes between deploy and build, so you can’t just do a find/replace for the exact string in DEPLOY since the value is the $CODEBUILD_SRC_DIR that was in BUILD.
For each function in the serverless-state.json, you will see an artifact property that looks similar to:
"artifact": "/codebuild/output/src887072543/src/.serverless/function.zip"
while it should actually look like this:"artifact": ".serverless/function.zip"
To work around this issue, I simply added the following two lines in my BUILD commands, immediately above the ‘serverless deploy …’ statement.
- sed -i 's/\/codebuild\/output//g' artifacts/${!stage}/serverless-state.json
- sed -i 's/\/src.*\//.serverless\//g' artifacts/${!stage}/serverless-state.json
Note: I am using the ‘${!stage}’ value in my code, but this may be different in your implementation - probably $ENV.
This will transform the “/codebuild/output/src887072543/src/.serverless/function.zip” statements to “.serverless/function.zip”, allowing the deploy process to find the file without error.
This took me a while to figure out, so I hope it helps others that may be experiencing the same issue.