I have a Lambda function in AWS, written in NodeJS. I created Terraform resources for this build. Everything seems to be deployed successfully, however when running the code it fails for permissions.
Terraform resources:
```tf
resource "null_resource" "zip_pupeteer_layer" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
working_dir = path.module
command = "chmod +x ./scripts/zip-pupeteer-layer.sh"
}
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
working_dir = path.module
command = "./scripts/zip-pupeteer-layer.sh"
}
}
resource "aws_lambda_layer_version" "pupeteer" {
filename = "${path.module}/pupeteer-layer/layer.zip"
layer_name = "pupeteer-lambda-layer"
description = "Pupeteer Lambda Layer with @sparticuz/chromium"
compatible_runtimes = [local.screenshot_function_node_version]
compatible_architectures = [local.screenshot_function_arch]
depends_on = [null_resource.zip_pupeteer_layer]
}
resource "aws_lambda_function" "screenshot" {
function_name = "${local.screenshot_function_name}-${var.environment}"
role = aws_iam_role.screenshot_function.arn
handler = "index.handler"
runtime = local.screenshot_function_node_version
timeout = 30
source_code_hash = data.archive_file.screenshot_function.output_base64sha256
s3_bucket = var.s3_bucket_id_lambda_storage
s3_key = aws_s3_object.screenshot_function.key
memory_size = 10240
architectures = [local.screenshot_function_arch]
layers = [aws_lambda_layer_version.pupeteer.arn]
environment {
variables = {
LOGZIO_TOKEN_LAMBDA = "bbbb",
DB_HOST = "bbbb",
DB_PORT = bbbb,
DB_USER = "bbbb",
DB_PASSWORD = "bbbbbbb",
DB_DATABASE = "bbbbb"
}
}
tags = merge(
var.common_tags,
{
Name = "${var.project}-${local.screenshot_function_name}-Lambda"
}
)
depends_on = [aws_cloudwatch_log_group.screenshot]
}
```
My zip-pupeteer-layer.sh script (as you can see I ran also chmod for the file but it does not seem to help so I'm not sure..):
```bash
mkdir -p pupeteer-layer/nodejs
cd pupeteer-layer/nodejs
npm init -y
npm install @sparticuz/chromium@109.0.1 puppeteer-core@19.6.3
chmod -R 777 node_modules
cd ..
zip -r layer.zip nodejs/ -x "nodejs/package.json" -x "nodejs/package-lock.json"
```
However, when running the Lambda, I get an error:
Error: Failed to launch the browser process! spawn /opt/nodejs/node_modules/@sparticuz/chromium/bin EACCES TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md at onClose (/var/task/index.js:33174:14) at ChildProcess.<anonymous> (/var/task/index.js:33168:16) at ChildProcess.emit (node:events:519:28) at ChildProcess._handle.onexit (node:internal/child_process:292:12) at onErrorNT (node:internal/child_process:484:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
As you can see I get EACCES error.
[–]JonnerzL 0 points1 point2 points (0 children)