Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difficulties using aws-sdk-rust with aws-lambda-rust-runtime #345

Closed
Franck-Q opened this issue Sep 9, 2021 · 3 comments
Closed

difficulties using aws-sdk-rust with aws-lambda-rust-runtime #345

Franck-Q opened this issue Sep 9, 2021 · 3 comments

Comments

@Franck-Q
Copy link

Franck-Q commented Sep 9, 2021

Hello, I'm trying to compile a rust lambda function using the aws-sdk-rust but having issues with it. Here's some info:

rust code:

use lambda::{handler_fn, Context};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Sync + Send + 'static>;

#[tokio::main]
async fn main() -> Result<(), Error> {
    lambda::run(handler_fn(handler)).await?;
    Ok(())
}

async fn handler(event: Value, _: Context) -> Result<Value, Error> {
    let shared_config = aws_config::load_from_env().await;
    let client = Client::new(&shared_config);
    let req = client.list_tables().limit(10);
    let resp = req.send().await?;
    println!("Current DynamoDB tables: {:?}", resp.table_names);
    Ok(())
}

Cargo.toml:

[package]
name = "lambda_sdk"
version = "0.1.0"
edition = "2018"

[dependencies]
lambda = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
serde_json = "1.0"
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "v0.0.17-alpha", package = "aws-config" }
aws-sdk-dynamodb = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "v0.0.17-alpha", package = "aws-sdk-dynamodb" }
tokio = { version = "1", features = ["full"] }

compilation (all worked before changing the lambda function to add the SDK):

  1. cross-compilation
    cargo build --release --target x86_64-unknown-linux-musl
  2. docker linux
    rustup target add x86_64-unknown-linux-musl && cargo build --release --target x86_64-unknown-linux-musl
  3. cdk synth myStack
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';

export class LookupIAMRoleStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const target = 'x86_64-unknown-linux-musl';
        new lambda.Function(this, 'lambdaSDK', {
            code: lambda.Code.fromAsset('lambda/lambda_sdk', {
                bundling: {
                    command: [
                        'bash', '-c',
                        `rustup target add ${target} && cargo build --release --target ${target} && cp target/${target}/release/lambda_sdk /asset-output/bootstrap`
                    ],
                    image: cdk.DockerImage.fromRegistry('rust:1.55-slim')
                }
            }),
            functionName: 'TestLambdaSDK',
            handler: 'main',
            runtime: lambda.Runtime.PROVIDED_AL2  // defines an AWS Lambda resource
        });
    }
}

all generate the exact same error message (with different path obviously):

Compiling syn-mid v0.5.0
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/mnt/target/release/build/ring-e3ac515dcadd1e70/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-musl")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-unknown-linux-musl = None
  CC_x86_64_unknown_linux_musl = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-unknown-linux-musl = None
  CFLAGS_x86_64_unknown_linux_musl = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/mnt/target/x86_64-unknown-linux-musl/release/build/ring-d2b907aa8e6446d7/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  thread 'main' panicked at 'failed to execute ["musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/mnt/target/x86_64-unknown-linux-musl/release/build/ring-d2b907aa8e6446d7/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace```
@seanpianka
Copy link
Contributor

seanpianka commented Sep 13, 2021

Hi @Franck-Q

From the stacktrace:

  thread 'main' panicked at 'failed to execute ["musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/mnt/target/x86_64-unknown-linux-musl/release/build/ring-d2b907aa8e6446d7/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9

It failed to execute $ musl-gcc ... because No such file or directory (os error 2)'. Please check that musl-gcc is installed on your host.

See the related issue: briansmith/ring#563 (comment)

@Franck-Q
Copy link
Author

Franck-Q commented Sep 13, 2021

Thank you @seanpianka (and sorry, the answer was in the question, I just needed someone to point it out :) ). In case someone has the same issue, running the following command fixed the issue: apt-get install -y gcc-multilib musl-tools
I got further, but now I'm getting the following error message: (or should I open a different issue)

Compiling futures-util v0.3.5
error[E0432]: unresolved import `futures_core::core_reexport`
  --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/lib.rs:51:9
   |
51 | pub use futures_core::core_reexport;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `core_reexport` in the root

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: could not compile futures-util

Here's my cargo.toml file:

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "v0.0.17-alpha", package = "aws-config" }
aws-sdk-dynamodb = { git = "https://github.com/awslabs/aws-sdk-rust", tag = "v0.0.17-alpha", package = "aws-sdk-dynamodb" }
tokio = { version = "1", features = ["full"] }
lambda = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
serde_json = "1.0"

cargo tree relevant parts:

├── aws-config v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.17-alpha#74cd8a14)
│   ├── aws-hyper v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.17-alpha#74cd8a14)
│   │   ├── aws-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.17-alpha#74cd8a14)
│   │   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.17-alpha#74cd8a14)
│   │   │   │   ├── hyper v0.14.12
│   │   │   │   │   ├── futures-util v0.3.5

@seanpianka
Copy link
Contributor

Happy to help! Try to update your dependencies with $ cargo update and see if that fixes the issue? If not, $ cargo clean and re-compile.

If the issue persists, I would suggest opening a new issue with a more specific title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants