How to fix Error: ENOENT: no such file or directory, mkdir in aws lambda with docker

Viewed 15

I have created a lambda function and I am deploying it with docker to was lambda. Testing locally everything works fine as shown below

āžœ  ~ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{
  "dependencies": {
    "@react-navigation/native": {
      "version": "5.9.8",
      "dependencies": {
        "react": "17.0.1",
        "react-native": "0.64.0"
      }
    }
  }
}'
{"statusCode":200,"body":"{\"message\":\"Dependencies successfully processed.\",\"manifest\":{\"@react-navigation/native\":{\"version\":\"5.9.8\",\"url\":\"https://dependency-runner.s3.us-east-2.amazonaws.com/v1/packages/@react-navigation/native/5.9.8.bundle.js\"}}}","headers":{"Content-Type":"application/json","Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":true,"Access-Control-Allow-Headers":"Origin,Accept,Content-Type","Access-Control-Allow-Methods":"OPTIONS,POST,GET"}}%

But when I deploy build, push and use it, it always gives the error {"message":"ENOENT: no such file or directory, mkdir '/var/task/nodedownload/1804e297a6b49b811d3898ad69eea9c84d5e42e1fe1c741b2b9f8b18890aef86'"}%

Here is my dockerfile

FROM public.ecr.aws/lambda/nodejs:14

RUN yum update -y \
    && yum install -y \
        wget \
        curl \
        tar \
        make \
        autoconf \
        expectsudo \
        openssl-devel \
    && yum -y groupinstall "Development Tools"

ENV IS_LOCAL=0
ENV FILESYSTEM_PATH=/var/task
ENV NODE_MODULES_PATH=/var/task/node_modules

RUN chown $USER -R 777  /var
RUN chown $USER -R 777  /home 

WORKDIR /var/task
COPY package.json .

RUN npm install

RUN npm install --global yarn
COPY . .
RUN ./node_modules/.bin/babel src -d ./

CMD [ "index.handler" ]

and the part causing issues is this I think WorkingDirectory is generated as below,

 let hash = crypto.createHash("sha256");
      hash.update(JSON.stringify(body), "utf8");
      let checksum = hash.digest("hex");

      const workingDirectory = path.join(ROOT_DIR, checksum);
      const manifestPath = path.join(workingDirectory, "manifest.json");

      console.log("WORKING DIR IS"+ workingDirectory )

     if (!fs.existsSync(workingDirectory)){
            console.log("Directory doesn't exist. Creating");
            fs.mkdirSync(workingDirectory, { recursive: true });
        }

How do I solve this. I cannot even see contents of console.log on cloudwatch.

0 Answers
Related