{"id":894,"date":"2020-12-02T05:58:44","date_gmt":"2020-12-01T20:58:44","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/?p=894"},"modified":"2020-12-08T15:27:57","modified_gmt":"2020-12-08T06:27:57","slug":"aws_lambda_container_image_support_jp","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/12\/02\/aws_lambda_container_image_support_jp\/","title":{"rendered":"AWS\u306e\u65b0\u6a5f\u80fd\u300cAWS Lambda Container Image Support\u300d\u3092\u7528\u3044\u3066\u3001\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u74b0\u5883\u306e\u79fb\u884c\u3092\u691c\u8a3c\u3057\u307e\u3057\u305f"},"content":{"rendered":"

2020\u5e7411\u670830\u65e5\u304b\u3089\u958b\u50ac\u3055\u308c\u3066\u3044\u308bAWS\u306e\u30b0\u30ed\u30fc\u30d0\u30eb\u30ab\u30f3\u30d5\u30a1\u30ec\u30f3\u30b9 AWS re:Invent 2020<\/a> \u306b\u3066\u3001 \u300cAWS Lambda Container Image Support\u300d<\/a> \u3068\u3044\u3046\u65b0\u30b5\u30fc\u30d3\u30b9\u304c\u767a\u8868\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n

AWS Lambda Container Image Support\u306f\u3001AWS\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30b3\u30f3\u30d4\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u300cAWS Lambda\u300d\u306b\u3066\u3001\u4eee\u60f3\u30b3\u30f3\u30c6\u30ca\u6280\u8853\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u753b\u671f\u7684\u306a\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002<\/p>\n

AWS Lambda Container Image Support\u306e\u30e1\u30ea\u30c3\u30c8<\/h3>\n

\u4eca\u56de\u306eAWS Lambda Container Image Support\u306e\u30ea\u30ea\u30fc\u30b9\u306b\u3088\u308a\u3001AWS Lambda\u3067\u4eee\u60f3\u30b3\u30f3\u30c6\u30ca\u6280\u8853\u300cDocker\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

Docker\u30b3\u30f3\u30c6\u30ca\u30d9\u30fc\u30b9\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092AWS Lambda\u4e0a\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3053\u3068\u3067\u3001\u3053\u308c\u307e\u3067AWS Lambda\u3067\u306f\u96e3\u3057\u304b\u3063\u305f\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u5bfe\u5fdc\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u4f8b\u3068\u3057\u3066\u306f\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

1. \u30e9\u30a4\u30d6\u30e9\u30ea\u4f9d\u5b58\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u6d3b\u7528\u3059\u308b<\/h4>\n

AWS Lambda Container Image Support\u306b\u3088\u3063\u3066\u3001\u30b3\u30f3\u30c6\u30ca\u30a4\u30e1\u30fc\u30b8\u306bAWS CLI\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u305d\u308c\u306b\u3088\u308a\u3001AWS SDK\u3067\u306f\u7528\u610f\u3055\u308c\u3066\u3044\u306a\u3044\u300cs3 sync\u300d\u3092\u306f\u3058\u3081\u3068\u3057\u3066\u3001OS\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u7279\u5b9a\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u4f9d\u5b58\u3059\u308b\u6a5f\u80fd\u30fb\u30b3\u30de\u30f3\u30c9\u3092\u3001AWS Lambda\u3067\u3082\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

2. \u4ed6\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u74b0\u5883\u3092AWS Lambda\u3078\u79fb\u884c\u3059\u308b<\/h4>\n

AWS Lambda Container Image Support\u3092\u7528\u3044\u308c\u3070\u3001Azure Functions\u306e\u3088\u3046\u306a\u30b3\u30f3\u30c6\u30ca\u30a4\u30e1\u30fc\u30b8\u4e0a\u3067\u7a3c\u50cd\u3059\u308b\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3001AWS Lambda\u4e0a\u3067\u3082\u7a3c\u50cd\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u4f8b\u3048\u3070\u3001Azure Functions\u306b\u3066Web-API\u30b5\u30fc\u30d0\u30fc\u306e\u30b3\u30f3\u30c6\u30ca\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u7a3c\u50cd\u3057\u3066\u3044\u308b\u5834\u5408\u3001Proxy\u30e9\u30a4\u30d6\u30e9\u30ea\u3068API Gateway\u3092\u5229\u7528\u3057\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092AWS Lambda\u3078\u79fb\u884c\u3059\u308b\u3053\u3068\u3082\u691c\u8a0e\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u306f\u3053\u306e\u30b1\u30fc\u30b9\u3092\u60f3\u5b9a\u3057\u3001Azure Functions Container Image\u3067\u7a3c\u50cd\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092AWS Lambda\u306b\u79fb\u884c\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u3001\u691c\u8a3c\u3092\u884c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

Azure Functions\u304b\u3089AWS Lambda\u3078\u306e\u79fb\u884c\u306e\u691c\u8a3c<\/h3>\n

\u79fb\u884c\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u3001\u3053\u3061\u3089\u3067\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30fc\u30c9\u3092\u63a1\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u79fb\u884c\u4f5c\u696d\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\uff08\u30b7\u30b9\u30c6\u30e0\u69cb\u6210\u56f3\uff09\u306f\u6b21\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n

\"\"<\/p>\n

\u5b9f\u65bd\u3057\u305f\u4f5c\u696d<\/h4>\n

\u307e\u305a\u306f\u3001AWS Lambda Container Image Support\u3092\u52d5\u4f5c\u3055\u305b\u308b\u305f\u3081\u306b\u3001Microsoft Azure\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u74b0\u5883\u300cAzure Functions\u300d\u3067\u7a3c\u50cd\u3057\u3066\u3044\u308bDocker\u30a4\u30e1\u30fc\u30b8\u306b\u5bfe\u3057\u3066\u3001AWS Lambda Runtime Interface Client\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u3053\u306e\u30b3\u30f3\u30c6\u30ca\u306bLambda\u30cf\u30f3\u30c9\u30e9\u30fc\u3092\u52a0\u3048\u3001\u30a8\u30f3\u30c8\u30ea\u30fc\u30dd\u30a4\u30f3\u30c8\u306f\u30cf\u30f3\u30c9\u30e9\u30fc\u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u306bDockerfile\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n

Dockerfile\u306e\u8a2d\u5b9a\u4f8b\uff1a<\/h4>\n

Dockerfile\u3067\u306fAWS Lambda Runtime Client\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n

# Azure Functions Container\nFROM xblood\/azurefunctionsimage:v1.0.0\n\nARG FUNCTION_DIR="\/home\/app\/"\nARG RUNTIME_VERSION\nARG DISTRO_VERSION\n\nRUN apt-get install -y libtool autoconf automake make cmake\n# build-base, libexecinfo-dev, libcurl\nRUN apt-get install -y curl build-essential\nRUN pip install awscli\nARG AWS_ACCESS_KEY_ID\nARG AWS_SECRET_ACCESS_KEY\nARG AWS_SESSION_TOKEN\nENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}\nENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}\nRUN mkdir -p ${FUNCTION_DIR}\n\n# Copy Lambda Handler\nCOPY handler.py ${FUNCTION_DIR}\n\n# Install AWS Lambda Runtime Interface Client\nRUN python${RUNTIME_VERSION} -m pip install \\\n    awslambdaric \\\n    --target \/home\/app\/\n\nWORKDIR ${FUNCTION_DIR}\n\n# Set the CMD to handler\nENTRYPOINT [ "\/usr\/local\/bin\/python", "-m", "awslambdaruntimeclient" ]\nCMD [ "handler.lambda_handler" ]<\/code><\/pre>\n

\u203b \u672cDockerfile\u3067\u6307\u5b9a\u3057\u3066\u3044\u308b xblood\/azurefunctionsimage \u306f \u3053\u3061\u3089\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a> \u306b\u6cbf\u3063\u3066\u4e8b\u524d\u4f5c\u6210\u3055\u308c\u305f\u30a4\u30e1\u30fc\u30b8\u3067\u3059<\/p>\n

Docker Image\u306e\u30d3\u30eb\u30c9<\/h4>\n

\u7d9a\u3044\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u30b3\u30f3\u30c6\u30ca\u3092\u30d3\u30eb\u30c9\u3057\u307e\u3057\u305f\u3002<\/p>\n

docker build . \\\n-f Dockerfile \\\n-t lambda-container-image \\\n--build-arg AWS_ACCESS_KEY_ID="[YOUR AWS ACCESS KEY ID]" \\\n--build-arg AWS_SECRET_ACCESS_KEY="[YOUR AWS SECRET ACCESS KEY]" \\\n--build-arg RUNTIME_VERSION="3.8" \\\n--build-arg DISTRO_VERSION="3.12"<\/code><\/pre>\n

ECR\u3078\u306e\u30d7\u30c3\u30b7\u30e5<\/h4>\n

\u4f5c\u6210\u3057\u305f\u30b3\u30f3\u30c6\u30ca\u30a4\u30e1\u30fc\u30b8\u306b\u30bf\u30b0\u3092\u8a2d\u5b9a\u3057\u3001Amazon Elastic Container Registry(ECR)\u306b\u30d7\u30c3\u30b7\u30e5\u3057\u307e\u3057\u305f\u3002
\n\u203b\u4e8b\u524d\u306bECR\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u4f5c\u6210\u3068Docker\u30ed\u30b0\u30a4\u30f3\u304c\u5fc5\u8981\u3067\u3059<\/p>\n

docker push xxxxxxxxxxxx.dkr.ecr.sa-east-1.amazonaws.com\/lambda-container-image:latest\n<\/code><\/pre>\n

Lambda\u306e\u4f5c\u6210<\/h4>\n

\u6b21\u306b\u3001AWS Lambda Container Image Support\u3092\u4f7f\u3063\u3066Lambda\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u4eca\u56de\u306fAWS CLI\u3092\u5229\u7528\u3057\u3001IAM\u30ed\u30fc\u30eb\u306f\u4e0b\u8a18\u30dd\u30ea\u30b7\u30fc\u3067\u4e8b\u524d\u306b\u4f5c\u6210\u3057\u3066\u304a\u304d\u307e\u3057\u305f\u3002<\/p>\n

IAM\u30ed\u30fc\u30eb\u30dd\u30ea\u30b7\u30fc\u4f8b( lambda-container-image-iam-role )<\/h4>\n
{\n   "Statement":[\n      {\n         "Sid":"VisualEditor0",\n         "Effect":"Allow",\n         "Action":[\n            "ecr:SetRepositoryPolicy",\n            "ecr:GetRepositoryPolicy"\n         ],\n         "Resource":"arn:aws:ecr:<region>:<account>:repository\/<repo name>\/"\n      }\n   ]\n}<\/code><\/pre>\n

AWS Lambda Container Image Support\u306b\u3088\u3063\u3066\u8ffd\u52a0\u3055\u308c\u305f ImageUri \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3001\u5148\u7a0b\u306e\u624b\u9806\u3067ECR\u306bPush\u6e08\u307f\u306e\u30b3\u30f3\u30c6\u30ca\u30a4\u30e1\u30fc\u30b8\u3092\u6307\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n

aws lambda create-function \\\n--function-name lambda-container-image-function \\\n--package-type Image \\\n--Image URI=xxxxxxxxxxxx.dkr.ecr.sa-east-1.amazonaws.com\/lambda-container-image:latest \\\n--role arn:aws:iam::xxxxxxxxxxxx:role\/lambda-container-image-iam-role<\/code><\/pre>\n

Lambda\u3092\u8d77\u52d5\u3059\u308b<\/h4>\n

AWS \u30de\u30cd\u30b8\u30e1\u30f3\u30c8\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u4f5c\u6210\u3057\u305fLambda\u3092\u30c6\u30b9\u30c8\u3059\u308b\u3068\u3001Lambda\u95a2\u6570\u304c\u6b63\u5e38\u306b\u5b9f\u884c\u3055\u308c\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n

\"\"<\/p>\n

\u3088\u308a\u5b9f\u8df5\u7684\u306a\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u5bfe\u5fdc\u3059\u308b\u306b\u306f<\/h4>\n

\u4eca\u56de\u306f\u691c\u8a3c\u306e\u305f\u3081\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30fc\u30c9\u3092\u7528\u3044\u307e\u3057\u305f\u304c\u3001\u5b9f\u969b\u306e\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092AWS Lambda\u3078\u79fb\u884c\u3059\u308b\u969b\u3084\u3001\u30de\u30eb\u30c1\u30af\u30e9\u30a6\u30c9\u6226\u7565\u3092\u63a1\u7528\u3059\u308b\u969b\u306b\u306f\u3001\u5404\u30af\u30e9\u30a6\u30c9\u30d9\u30f3\u30c0\u30fc\u306eAPI\u3092\u5dee\u7570\u3092\u8003\u616e\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n

\u6628\u4eca\u3067\u306f Serverless Multicloud Library<\/a> \u306e\u3088\u3046\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u6d3b\u7528\u3057\u3066\u89e3\u6c7a\u3067\u304d\u308b\u30b1\u30fc\u30b9\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n

AWS Lambda\u306e\u30d3\u30b8\u30cd\u30b9\u6d3b\u7528\u3092\u30b5\u30dd\u30fc\u30c8<\/h3>\n

\u682a\u5f0f\u4f1a\u793eMMM\u306f \u3001AWS Lambda\u306e\u30d3\u30b8\u30cd\u30b9\u6d3b\u7528\u306b\u8c4a\u5bcc\u306a\u5b9f\u7e3e\u3092\u6301\u3063\u3066\u304a\u308a\u3001AWS Lambda\u306eAWS\u30b5\u30fc\u30d3\u30b9\u30c7\u30ea\u30d0\u30ea\u30fc\u30d1\u30fc\u30c8\u30ca\u30fc\u306b\u3082\u8a8d\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n

MMM\u306f\u3001\u591a\u7a2e\u591a\u69d8\u306aAWS\u30de\u30cd\u30fc\u30b8\u30c9\u30b5\u30fc\u30d3\u30b9\u3092\u30af\u30e9\u30a6\u30c9\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u6e96\u62e0\u3057\u305f\u5f62\u3067\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30af\u30e9\u30a6\u30c9\u306e\u771f\u306e\u65e8\u5473\u3067\u3042\u308b\u67d4\u8edf\u6027\u3084\u4fca\u654f\u6027\u3092\u304a\u5ba2\u69d8\u306e\u30d3\u30b8\u30cd\u30b9\u306b\u7d44\u307f\u8fbc\u3080\u3053\u3068\u3092\u5f97\u610f\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305fAWS Lambda Container Image Support\u3082\u542b\u3081\u3001 \u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\uff08AWS Lambda\uff09 \u306e\u5c0e\u5165\u3084\u7121\u6599\u76f8\u8ac7\u306b\u95a2\u3057\u3066\u306f\u6b21\u306e\u30da\u30fc\u30b8\u3088\u308a\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n