question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS -Still incorrect path when using $CODEBUILD_SRC_DIR

See original GitHub issue

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.

Is it sill not fixed ?

Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
medikoocommented, Dec 6, 2019

@soelchma is there any expected date to solve this?

Hopefully patch will land next week

2reactions
jplandry908commented, 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.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting AWS CodeBuild
Issue: When you run a build, the UPLOAD_ARTIFACTS build phase fails with the error Failed to upload artifacts: Invalid arn . Possible cause:...
Read more >
AWS Code build don't fail if no test files found - Stack Overflow
I created an empty surefire report xml, dummy.xml under <java_src_root>/target/surefire-reports <?xml version="1.0" encoding="UTF-8"?> ...
Read more >
10 smart ways to use AWS CodeBuild | by Moha Alsouli
1. Builds, ad-hoc. · 2. Builds, part of a CodePipeline. · 3. Builds, docker. · 4. Unit testing. · 5. Automation testing. ·...
Read more >
update-project — AWS CLI 2.9.8 Command Reference
Use the CodeBuild console to start creating a build project. ... value of the built-in CODEBUILD_SRC_DIR environment variable, or the path to an...
Read more >
Find Answers to AWS Questions about AWS CodeBuild
Browse through AWS CodeBuild questions or showcase your expertise by answering ... Hi, I am using this config in a buildspec, but builds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found