-
Docker 웹 사이트의 Get Docker 페이지로 이동합니다. 요구 사항에 맞는 Docker Desktop 애플리케이션을 선택합니다. 제공된 지침에 따라 Docker Desktop을 설치합니다.
-
로컬 머신에서 다음 3개의 파일이 포함된 폴더 하나를 생성합니다. Dockerfile, 라이브러리가 포함된 requirements.txt, import 구문이 포함된 app.py.
참고: Amazon Elastic Container Registry(Amazon ECR) 퍼블릭 레지스트리용 최신 버전의 Python을 사용하십시오.
다음 예시 Dockerfile은 Python 3.8을 사용합니다.
FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]
다음 예시 app.py 파일에는 예시 import 구문이 포함되어 있습니다.
import sysdef handler(event, context):
return 'Hello from AWS Lambda using Python' + sys.version + '!'
-
docker build 명령과 이미지 이름을 사용하여 Docker 이미지를 빌드합니다.
다음은 "hello-world" 예시를 사용한 docker build 명령입니다.
docker build -t hello-world .
참고: Amazon ECR 퍼블릭 리포지토리에서 가져올 때 인증 오류가 발생하는 경우 Amazon ECR Public 문제 해결을 참조하십시오.
-
docker run 명령으로 Docker 이미지를 시작합니다.
다음은 "hello-world" 예시를 사용한 docker run 명령입니다.
docker run -p 9000:8080 hello-world
-
GitHub 웹 사이트에 있는 AWS의 Lambda Runtime Interface Emulator(RIE)를 사용하여 애플리케이션을 테스트합니다. 새 터미널 창에서 curl 명령을 실행하여 다음 엔드포인트로 이벤트를 게시합니다.
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
이 명령은 컨테이너 이미지에서 실행 중인 함수를 간접 호출한 다음 응답을 반환합니다.
-
Amazon ECR 레지스트리에 대해 Docker CLI를 인증합니다.
명령의 계정 ID와 AWS 리전을 사용자의 계정 ID 및 리전으로 변경합니다.
다음은 Amazon ECR 레지스트리에 대해 Docker CLI를 인증하는 예시 명령입니다.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com
-
create-repository 명령을 사용하여 Amazon ECR에 리포지토리를 생성합니다.
다음은 create-repository 예시 명령입니다.
aws ecr create-repository --repository-name hello-world --image-scanning-configuration scanOnPush=true --image-tag-mutability MUTABLE
-
docker tag 명령을 사용하여 리포지토리 이름과 일치하도록 이미지에 태그를 지정합니다. 그런 다음 docker push 명령을 사용하여 이미지를 Amazon ECR에 배포합니다.
명령의 계정 ID와 AWS 리전을 사용자의 계정 ID 및 리전으로 변경합니다.
다음은 docker tag 예시 명령입니다.
docker tag hello-world:latest 123456789012.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest
다음은 docker push 예시 명령입니다.
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest
-
Amazon ECR 컨테이너 레지스트리에 컨테이너 이미지가 준비되면 Lambda 함수를 생성하고 실행합니다. 자세한 내용은 컨테이너 이미지를 사용하여 Lambda 함수 생성을 참조하십시오.