库贝还是假的?是一款有趣的迷你游戏,玩家的目标是正确猜测 ChatGPT 生成的单词是真正的 Kubernetes 术语还是编造的。
不要忘记在 LinkedIn / Twitter 上分享您的结果!
Python
新项目管理
码头工人
AWS SAM CLI
酿造安装 aws/tap/aws-sam-cli
分叉这个存储库
安装依赖项
npm 安装
该存储库包含本地运行 AWS Lambda 以及使用 CloudFormation 模板将其部署到 AWS 所需的文件。
在template.yml
中,提供环境变量OPENAI_API_KEY
和OPENAI_MODEL_NAME
的值。
为openai
Python 包创建本地 Lambda 层:
pip install -r requests.txt -t libs/python
Lambda 可以使用sam
在本地运行:
sam 本地启动-api
此命令启动在localhost:3000
中运行的服务器。命令输出应如下所示:
Mounting GenerateKubernetesTermFunction at http://127.0.0.1:3000/generate [GET] You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template 2023-07-20 11:58:51 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:3000 2023-07-20 11:58:51 Press CTRL+C to quit
当通过localhost:3000/generate
调用 Lambda 时,会显示更多日志:
Invoking lambda.lambda_handler (python3.10) OpenAILambdaLayer is a local Layer in the template Local image is up-to-date Building image..................... Using local image: samcli/lambda-python:3.10-x86_64-b22538ac72603f4028703c3d1. Mounting kube-or-fake/lambda as /var/task:ro,delegated, inside runtime container START RequestId: b1c733b3-8449-421b-ae6a-fe9ac2c86022 Version: $LATEST END RequestId: b1c733b3-8449-421b-ae6a-fe9ac2c86022 REPORT RequestId: b1c733b3-8449-421b-ae6a-fe9ac2c86022
注意:可能会要求您提供本地计算机凭据,以允许sam
与本地 docker 守护进程交互。
Lambda 代码存在于lambda/lambda.py
中,其中lambda_handler
是处理程序。随意探索吧!
请注意,Lambda docker 映像将在每次调用时构建,因此在更改 Lambda 代码时无需重新运行sam local start-api
(但对template.yml
的更改确实需要重新运行) 。
我们也使用sam
来做到这一点:
山姆构建 山姆部署
按照命令的输出查看新 Lambda 的创建位置。
在scripts/words.js
中,将GENERATOR_URL
更改为http://127.0.0.1:3000/generate
(如果在本地运行)或您的远程 Lambda URL。
在任何浏览器上打开index.html
并开始播放。如果配置正确,您应该会看到 Lambda 调用(通过本地日志或 CloudWatch)。