0
2

AWS Lambda にPythonウェブサーバーを立てる最小のDockerfileを書いた

Posted at

関数URLにアクセスすれば
image.png

これが動くなら言語、フレームワーク問わずどんなウェブサーバーも動かせそうですね

FROM public.ecr.aws/lambda/python:3.12
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.3 /lambda-adapter /opt/extensions/lambda-adapter
ENV PORT=8080
RUN printf "\n\
import os, http.server, socketserver\n\
class MyHandler(http.server.SimpleHTTPRequestHandler):\n\
    def do_GET(self):\n\
        self.send_response(200)\n\
        self.send_header('Content-type', 'text/html')\n\
        self.end_headers()\n\
        self.wfile.write(b'Hello World from Lambda')\n\
PORT = int(os.getenv('PORT'))\n\
with socketserver.TCPServer(('', PORT), MyHandler) as httpd:\n\
    print(f'Serving on port {PORT}')\n\
    httpd.serve_forever()\n\
" > test_server.py
ENTRYPOINT python test_server.py
0
2
0

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
2