💡

AWS SAMを用いたローカル開発時におけるError building docker imageへの対応

2022/05/21に公開

AWS SAMを用いたローカル開発を行う際、以下のような手順を踏んでいます。

sam init --runtime=python3.8
cd sam-app
sam local start-api

ただ上記を実行した際、以下のエラーが発生することがありました。

samcli.commands.local.cli_common.user_exceptions.ImageBuildException: Error building docker image: pull access denied for public.ecr.aws/sam/emulation-python3.8, repository does not exist or may require 'docker login': denied: Your authorization token has expired. Reauthenticate and try again.

この時、以下を実行することでエラーを解消することができました。regionなどは環境に合わせて修正する必要があるかもしれません。

aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws

同様のエラーでお困りの方の参考になりましたら幸いです。

Discussion