You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AWS -Still incorrect path when using $CODEBUILD_SRC_DIR #6964
My 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.
I've the same issue as well, Once the script enters deployment stage in Pipeline everything seems to be fine, it uploads everything and generate the URL. but then it fails due to the same error with duplicating it's directories '/codebuild/output/src932745260/src/core/codebuild/output/src932745260/src/core/deployment_package/serverless-state.json'
Also, even when I specify --package flag, serverless.yml keep looking for nodeModules.zip, which is my Layer directory inside .serverless and ignores that I've packaged it inside deployment_package.
Also, this happens when I activate Layers in serverless.yml it searches for nodeModules.zip inside .serverless even though I used serverless deploy --package deployment_package --stage development
@ferasallaou I'm really sorry, other priorities took over this priority. Fix will definitely land (work on it has started), but at this point I cannot promise any specific release window
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.
Hey everyone, I just wanted to let you know that this issue should now be resolved in v4.4.17. If you encounter any further issues, feel free to reach out!
Activity
medikoo commentedon Nov 15, 2019
@soelchma thanks for report. Can you show full output with
SLS_DEBUG=*, and possibly track which exactly fs invocation crashes withENOENTerror?ferasallaou commentedon Nov 18, 2019
I've the same issue as well, Once the script enters deployment stage in Pipeline everything seems to be fine, it uploads everything and generate the URL. but then it fails due to the same error with duplicating it's directories
'/codebuild/output/src932745260/src/core/codebuild/output/src932745260/src/core/deployment_package/serverless-state.json'Also, even when I specify --package flag, serverless.yml keep looking for nodeModules.zip, which is my Layer directory inside .serverless and ignores that I've packaged it inside deployment_package.
medikoo commentedon Nov 18, 2019
@ferasallaou Can you show full output with
SLS_DEBUG=*?ferasallaou commentedon Nov 18, 2019
@medikoo Here you go
ferasallaou commentedon Nov 18, 2019
Also, this happens when I activate Layers in
serverless.ymlit searches for nodeModules.zip inside.serverlesseven though I usedserverless deploy --package deployment_package --stage developmentmedikoo commentedon Nov 21, 2019
@ferasallaou thank you, I see it clearly now. Fix will be introduced shortly
7 remaining items
ferasallaou commentedon Dec 6, 2019
@soelchma is there any expected date to solve this? I think it is a priority, I cannot complete Pipeline deployments because of this :(
medikoo commentedon Dec 6, 2019
Hopefully patch will land next week
ferasallaou commentedon Feb 18, 2020
@medikoo Any updates on this one? :(
medikoo commentedon Feb 19, 2020
@ferasallaou I'm really sorry, other priorities took over this priority. Fix will definitely land (work on it has started), but at this point I cannot promise any specific release window
kutscherma commentedon Feb 23, 2020
@medikoo Ok thank you!
danyfoo commentedon Feb 25, 2020
Hi a workaround solution I found.
Instead of using
$CODEBUILD_SRC_DIRvariable for the path of package I changed using a relative path.So you can change your serverless deploy to:
sls deploy --stage $env --package ./target/$env -v -r eu-central-1franciscomemoli commentedon Mar 6, 2020
didn't work for me, the serverless-state.json still having the full path 🤷♂️
debugguru commentedon Jan 8, 2021
Any update on this? This is still an issue
jplandry908 commentedon May 2, 2021
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.jsonNote: 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.
czubocha commentedon Dec 18, 2024
Hey everyone, I just wanted to let you know that this issue should now be resolved in v4.4.17. If you encounter any further issues, feel free to reach out!