0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LambdaとContainerとJavaとM2 Macbook。

Posted at

はじめに

コンテナを使ったLambda関数を作ったことなかったなー。と思い、業務でも活かせそうなjavaで試してみました。

どハマりしたので、情報共有です。

その1:The image manifest or layer media type for the source image〜

まず、デプロイ時に出るこのエラーです。

スクリーンショット 2025-01-11 6.03.37.png

The image manifest or layer media type for the source image xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/batch-demo-lambda@sha256:0aa7422dadc5f760ad4ac164fda2ff7219d97daac3264abc5ce690f070ea3f36 is not supported.

--provenance=falseの付与が必要。

docker buildに以下のオプションが必要でした。

この件は多くの記事で紹介されていました。

docker build --provenance=false -t batch-demo-lambda .

その2:Error: fork/exec /lambda-entrypoint.sh: exec format error

次にこのエラーです。

スクリーンショット 2025-01-11 6.13.06.png

--platform linux/amd64

ややこしいのですが、まずAppleシリコンのMacBookでは、--platform linux/amd64を明示しないとだめだよ!って記事を見かけたので、以下でビルドするようにしました。

docker build --provenance=false --platform linux/amd64 -t batch-demo-lambda 

そして、ランタイムもarm64側を選んでたのですが、どうしてもエラーが取れませんでした。

ただ、x86_64側だとエラーが出なくなり、不思議な感じでした。

スクリーンショット 2025-01-11 6.14.33.png

arm64とamd64の違いに気づけず。。

この記事を書いていて、ようやく原因に気づいたのですが、私がarm64amd64の違いに気づけてませんでした。。

Appleシリコン版はarm64なので、Lambdaのランタイムarm64で動かす場合は、--platformの明示的な指定は不要でした。

docker build --provenance=false -t batch-demo-lambda .

java.lang.ClassNotFoundException

スクリーンショット 2025-01-11 6.26.52.png

${LAMBDA_TASK_ROOT}/lib/にJARファイルを置く。

JARファイルは${LAMBDA_TASK_ROOT}直下ではなく、libに配置する必要がありました。

COPY target/batch_demo-1.0.jar ${LAMBDA_TASK_ROOT}/lib/

また、ここらの調査でもJava21Java27の違いに気づけず、時間を無駄に消費しました。。

余談:imagesが更新されない!

今回はコンソール上からの操作でしたが、ここの更新ボタンでイメージが更新されないのは地味にストレスでした。。

スクリーンショット 2025-01-11 6.38.00.png

まとめ

javaをコンテナに乗せて、Lambdaで動かすケースなんてないと思いますが、ネタ記事として公開してみます!

なお、log4jを使って以下のログを出すだけのサンプルにおける性能ですが、12秒くらいでした。(遅い)

21:40:22.749 [main] INFO  org.example.Main - Hello and welcome!
21:40:22.809 [main] INFO  org.example.Main - i = 1
21:40:22.809 [main] INFO  org.example.Main - i = 2
21:40:22.809 [main] INFO  org.example.Main - i = 3
21:40:22.809 [main] INFO  org.example.Main - i = 4
21:40:22.809 [main] INFO  org.example.Main - i = 5

REPORT Duration: 11618.42 ms	Billed Duration: 12085 ms	Memory Size: 128 MB	Max Memory Used: 115 MB	Init Duration: 466.01 ms	

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?