Skip to content

Getting invalid entrypoint when deploying via terraform #391

Description

@anuraags

Hi all,

Looking for a bit of help as I can't seem to work out how to debug further with my current issue (which may or may not be architecture related but I can't tell).

I'm building my rust executable for a lambda runtime and keep getting the InvalidEntrypoint error when invoking it. I'm currently deploying the function using terraform.

The code itself is basically just the code from examples/basic.rs copied into my main.rs file.

Here is the Dockerfile that I use:

# Contents from aws.Dockerfile

FROM rust:latest
RUN rustup target add x86_64-unknown-linux-gnu
RUN apt-get update && apt-get install -y build-essential

Here is my build script:

#!/bin/sh

RUST_TARGET="x86_64-unknown-linux-gnu" # corresponding with the above, set this to aarch64 or x86_64 -unknown-linux-gnu for ARM or x86 functions.
LAMBDA_ARCH="linux/amd64" # set this to either linux/arm64 for ARM functions, or linux/amd64 for x86 functions.
# RUST_VERSION="latest" # Set this to a specific version of rust you want to compile for, or to latest if you want the latest stable version.

docker build -f aws.Dockerfile -t rust-aws-build/1.0 .
docker tag rust-aws-build/1.0 rust-aws-build/1.0
docker run \
    --platform ${LAMBDA_ARCH} \
    --rm --user "$(id -u)":"$(id -g)" \
    -v "${PWD}":/usr/src/myapp -w /usr/src/myapp rust-aws-build/1.0 \
    cargo build --verbose -p rust_async_lambda --release --target ${RUST_TARGET}

And this is my terraform for the lambda function resource:

resource "null_resource" "rust_async_lambda_function_source" {
  triggers = {
    binary = base64sha256(filebase64("${path.module}/../rust-async-lambda/target/x86_64-unknown-linux-gnu/release/rust_async_lambda"))
  }
}

data "archive_file" "rust_async_lambda_archive" {
  output_path = "${path.module}/out/rust-async-lambda.zip"
  type        = "zip"

  source {
    content  = "${path.module}/../rust-async-lambda/target/x86_64-unknown-linux-gnu/release/rust_async_lambda"
    filename = "bootstrap"

  }
  depends_on = [null_resource.rust_async_lambda_function_source]
}


resource "aws_iam_role" "rust_async_lambda_exec_role" {
  name = "rust_async_lambda_exec_role"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Action = "sts:AssumeRole",
      Effect = "Allow"
      Sid    = ""
      Principal = {
        Service = "lambda.amazonaws.com"
      }
      }
    ]
  })
}

resource "aws_lambda_function" "rust_async_lambda" {
  function_name = "${var.app_name}-rust-async-lambda"
  filename      = data.archive_file.rust_async_lambda_archive.output_path
  handler       = "index.handler"
  source_code_hash = data.archive_file.rust_async_lambda_archive.output_base64sha256
  role = aws_iam_role.rust_async_lambda_exec_role.arn
  runtime = "provided.al2"

  environment {
    variables = {
      RUST_BACKTRACE = "1"
    }
  }

  tracing_config {
    mode = "Active"
  }
}

And I keep getting the error:

{"errorMessage":"RequestId: 8a5cc143-e3f8-457a-bbf0-640f8ee1012c Error: fork/exec /var/task/bootstrap: exec format error","errorType":"Runtime.InvalidEntrypoint"}

Anyone have any idea what's going on? I'm not getting any build errors during the cargo build and I can see the file is getting extracted correctly (with the bootstrap executable) in the AWS console.

Activity

  1. coltonweaver commented on Jan 6, 2022

    @coltonweaver
    Contributor

    Can you provide a bit of information about the host machine that you're building on?

  2. locked and limited conversation to collaborators on Feb 9, 2022
  3. converted this issue into a discussion #412 on Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions