我正在使用AWS SAM并对lambda进行了docker化。这是我的Dockerfile
FROM python:3.7-alpine
RUN apk update && \
apk upgrade && \
apk add bash && \
apk add --no-cache --virtual build-deps build-base gcc && \
pip install aws-sam-cli && \
apk del build-deps
WORKDIR /app/
RUN ls
COPY bin/sam_entrypoint.sh bin/
COPY lambda/hello_world/requirements.txt .
RUN pip install -r requirements.txt
EXPOSE 8000
ENTRYPOINT "bin/sam_entrypoint.sh"
这是我的docker-compose.yaml
version: '3.6'
services:
sam_app:
build:
context: .
dockerfile: Dockerfile
command: ["$PWD"]
image: sam:0.1
ports:
- "8000:8000"
volumes:
- .:/app
- /var/run/docker.sock:/var/run/docker.sock
这是我的bin/sam_entrypoint.sh
#!/bin/sh
set -ex
echo "Hello"
BASEDIR="${PWD}/lambda/"
/usr/local/bin/sam build \
--template lambda/template.yaml
/usr/local/bin/sam local start-api \
--template lambda/template.yaml \
--host 0.0.0.0 \
--port 8000 \
--docker-volume-basedir "${BASEDIR}" \
--docker-network sam-app_default \
--skip-pull-image
当我运行dc up
(在本地启动api)并点击http://0.0.0.0:8000/hello
时。我收到以下错误。
似乎安装正确,但是不确定我到底在做什么错。它一定是简单丢失的东西。我将不胜感激任何建议或帮助。
编辑:添加template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: index.lambda_handler
Runtime: python3.7
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get