Closed4

AWS LambdaでRustを使いたい

Shingo YamazakiShingo Yamazaki

とりあえず簡単な Lambda 関数を動かす

ランタイムは https://github.com/awslabs/aws-lambda-rust-runtime が本家っぽい。
RustをつかってAWS Lambdaを実装&AWS CDKでデプロイする | DevelopersIO

lambda = { package = "netlify_lambda", version = "0.2.0" }

https://crates.io/crates/netlify_lambda

リポジトリの README 見ると、参考リンクのコードとはだいぶ違う。
https://github.com/awslabs/aws-lambda-rust-runtime/releases/tag/v0.3.0

New: Almost everything!

て書いてて笑う。リポジトリのサンプルコードを正としてすすめるのがよさそう

Shingo YamazakiShingo Yamazaki

cargo-aws-lambda を使ったデプロイ

コンソールで Lambda 関数を作ってから

$ cargo aws-lambda arn:aws:lambda:us-east-1:***:function:helloRustLambda bootstrap
Preparing to deploy /Users/yamazaki/hello-aws-rust/target/lambda/release/bootstrap.zip to "us-east-1" helloRustLambda
Running docker with args run --rm -v /Users/yamazaki/hello-aws-rust:/code -v /Users/yamazaki/.cargo/registry:/root/.cargo/registry softprops/lambda-rust:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
   Compiling proc-macro2 v1.0.32
   Compiling syn v1.0.81
   Compiling autocfg v1.0.1
   Compiling log v0.4.14
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.0.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.1.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.2.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.3.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.4.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.5.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.6.rcgu.o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.build_script_build.1lifrrw6-cgu.7.rcgu.o" "-o" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb" "/code/target/lambda/release/build/log-94010d1a8c141ccb/build_script_build-94010d1a8c141ccb.59w1m9rvitk7nlv9.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/code/target/lambda/release/deps" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c147cd9c030850ef.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-7e62a3a07bb85bc1.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-000f77165d4d2d36.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7dc0cb59ed386ac6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-9248bfbd7273ac3d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-b75363fb938de39d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7bbe96f555da4ad6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a145493c64eeb044.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9577436fc6fce6bc.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b3376c0a2b35415c.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5708f6b2b59b6e0f.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-e9fd09201d99d6f4.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-914c6ef6f5cf354a.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1445b6c7903692a2.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: cc: error: missing argument to '-march='


error: aborting due to previous error

error: could not compile `log`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.0.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.1.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.10.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.11.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.12.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.13.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.14.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.15.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.2.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.3.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.4.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.5.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.6.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.7.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.8.rcgu.o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.build_script_build.eff469gd-cgu.9.rcgu.o" "-o" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae" "/code/target/lambda/release/build/proc-macro2-c3f4f1e72f2ba5ae/build_script_build-c3f4f1e72f2ba5ae.17y0y7vmm2w2u3sp.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/code/target/lambda/release/deps" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c147cd9c030850ef.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-7e62a3a07bb85bc1.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-000f77165d4d2d36.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7dc0cb59ed386ac6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-9248bfbd7273ac3d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-b75363fb938de39d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7bbe96f555da4ad6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a145493c64eeb044.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9577436fc6fce6bc.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b3376c0a2b35415c.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5708f6b2b59b6e0f.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-e9fd09201d99d6f4.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-914c6ef6f5cf354a.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1445b6c7903692a2.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: cc: error: missing argument to '-march='


error: aborting due to previous error

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.0.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.1.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.10.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.11.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.12.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.13.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.14.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.15.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.2.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.3.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.4.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.5.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.6.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.7.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.8.rcgu.o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.build_script_build.cb3kpn3m-cgu.9.rcgu.o" "-o" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3" "/code/target/lambda/release/build/syn-82b9b2acb0f1e3b3/build_script_build-82b9b2acb0f1e3b3.39136oonj09j6fho.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/code/target/lambda/release/deps" "-L" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c147cd9c030850ef.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-7e62a3a07bb85bc1.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-000f77165d4d2d36.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7dc0cb59ed386ac6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-9248bfbd7273ac3d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-b75363fb938de39d.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7bbe96f555da4ad6.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a145493c64eeb044.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9577436fc6fce6bc.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b3376c0a2b35415c.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5708f6b2b59b6e0f.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-e9fd09201d99d6f4.rlib" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-914c6ef6f5cf354a.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1445b6c7903692a2.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: cc: error: missing argument to '-march='


error: aborting due to previous error

error: build failed
Running docker failed, check output above

これもエラー。。。

このスクラップは2023/01/10にクローズされました