{"id":205266,"date":"2025-05-29T10:02:16","date_gmt":"2025-05-29T02:02:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205266\/"},"modified":"2025-05-29T10:02:16","modified_gmt":"2025-05-29T02:02:16","slug":"%e4%bd%bf%e7%94%a8-docker-%e5%88%9b%e5%bb%ba-aws-%e5%b1%82","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205266\/","title":{"rendered":"\u4f7f\u7528 Docker \u521b\u5efa AWS \u5c42"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528 Docker \u521b\u5efa AWS \u5c42<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528 Docker \u521b\u5efa AWS \u5c42\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17327056066746fd46e27fd.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u9700\u8981\u5728 aws \u4e2d\u4e3a lambda \u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5c42\uff0c\u5e76\u4e14\u8be5\u5c42\u5bf9\u5176\u64cd\u4f5c\u6709\u4e00\u4e9b so \u4f9d\u8d56\u9879\u65f6\uff0c\u56e0\u6b64\u6211\u4eec\u9047\u5230\u4e86\u95ee\u9898\uff0caws \u6587\u6863\u53ef\u80fd\u4e0d\u591f\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6240\u9700\u7684\u5c42\u4e2d\u6784\u5efa\u7f3a\u5c11\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/p>\n<p>\u597d\u5427\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 python 3.x \u548c pdf2image \u5e93\u6765\u5236\u4f5c\u6f14\u793a<\/p>\n<ul>\n<li>docker \u5b89\u88c5<\/li>\n<li>python 3.x<\/li>\n<li>aws cli \u914d\u7f6e\uff08\u53ef\u9009\uff09<\/li>\n<li>\u8bbf\u95ee aws lambda<\/li>\n<\/ul>\n<pre>mkdir lambda-layer\ncd lambda-layer\nmkdir python\ncd python\n<\/pre>\n<pre>pip3 install [your_dependencies] \\\n    --platform manylinux2014_x86_64 \\\n    --target . \\\n    --only-binary=:all: \\\n    --implementation cp \\\n    --python-version [tu_version_python] \\\n    --no-deps\n<\/pre>\n<p>pdf2image \u793a\u4f8b\uff1a<\/p>\n<pre>pip3 install pdf2image pillow \\\n    --platform manylinux2014_x86_64 \\\n    --target . \\\n    --only-binary=:all: \\\n    --implementation cp \\\n    --python-version 3.10 \\\n    --no-deps\n<\/pre>\n<pre>from ubuntu:22.04 as builder\n\nenv debian_frontend=noninteractive\n\nrun apt-get update &amp;&amp; apt-get install -y \\\n    python3.10 \\\n    python3-pip \\\n    binutils \\\n    zip \\\n    [tus_paquetes_adicionales] \\\n    --no-install-recommends \\\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\n\nworkdir \/lambda\nrun mkdir -p \/opt\/python\/lib\/python3.10\/site-packages\/bin\n\ncopy python\/ \/opt\/python\/lib\/python3.10\/site-packages\/\n\nrun cp [tus_binarios] \/opt\/python\/lib\/python3.10\/site-packages\/bin\/ &amp;&amp; \\\n    chmod 755 \/opt\/python\/lib\/python3.10\/site-packages\/bin\/*\n\nrun cd \/opt &amp;&amp; zip -r9 \/lambda\/layer.zip python\/\n\nfrom alpine:3.18\ncopy --from=builder \/lambda\/layer.zip \/\ncmd [\"\/bin\/sh\"]\n<\/pre>\n<pre># image build\ndocker build -t lambda-layer .\n\n# extract layer.zip\ndocker run --rm -v \"$(pwd)\":\/out lambda-layer cp \/layer.zip \/out\/\n<\/pre>\n<p>\u5b8c\u6210\u524d\u9762\u7684\u6b65\u9aa4\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u50cf\u5f80\u5e38\u4e00\u6837\u4e0a\u4f20\u56fe\u5c42\u5e76\u5c06\u5176\u5bfc\u5165\u5230\u6211\u4eec\u7684\u9879\u76ee\u4e2d<\/p>\n<pre>\nimport os\nimport sys\n\n#Configuring paths\nSITE_PACKAGES = '\/opt\/python\/lib\/python3.10\/site-packages'\nBIN_DIR = os.path.join(SITE_PACKAGES, 'bin')\nos.environ['PATH'] = f\"{BIN_DIR}:{os.environ['PATH']}\"\nsys.path.append(SITE_PACKAGES)\n\n#importing dependencies\nfrom pdf2image import [your_import]\n\ndef lambda_handler(event, context):\n    try:\n        # your code here\n        return {\n            'statusCode': 200,\n            'body': 'Success'\n        }\n    except Exception as e:\n        return {\n            'statusCode': 500,\n            'body': f'Error: {str(e)}'\n        }\n\n<\/pre>\n<ul>\n<li>aws lambda \u5c42\u6587\u6863<\/li>\n<li>python \u5305\u7ba1\u7406<\/li>\n<li>docker \u6587\u6863<\/li>\n<\/ul>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u4f7f\u7528 Docker \u521b\u5efa AWS \u5c42\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Docker \u521b\u5efa AWS&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205266","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205266"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205266\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}