所以我已经成功地让 Nuxt3 在 AWS Lambda 上运行,但是在过去的几天里我一直遇到问题让它与 Docker 图像很好地工作。我遇到问题的部分是处理程序,我很难弄清楚如何调用它。这是我到目前为止所拥有的:
Docker文件
FROM node:14-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json package-lock.json /app/
RUN npm install
RUN npm run build
COPY ./.output /app/.output
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
# You can overwrite command in `serverless.yml` template
CMD [".output/server/index.handler"]
serverless.yml
service: ssr-nuxt
frameworkVersion: '3'
plugins:
- serverless-offline
provider:
name: aws
ecr:
# In this section you can define images that will be built locally and uploaded to ECR
images:
appimage:
path: ./
stage: prod
region: ${opt:region, 'sa-east-1'}
iam:
role:
statements:
- Effect: "Allow"
Action:
- "s3:ListBucket"
Resource: { "Fn::Join" : ["", ["arn:aws:s3:::frontend-dev-serverlessdeploymentbucket-1q7esbsg18hf8", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
- Effect: "Allow"
Action:
- "s3:PutObject"
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::frontend-dev-serverlessdeploymentbucket-1q7esbsg18hf8"
- "Ref" : "ServerlessDeploymentBucket"
- "/*"
functions:
ssr-nuxt:
image:
name: appimage
events:
- schedule:
name: warmer-schedule-main
rate: rate(5 minutes)
enabled: true
input:
warmer: true
concurrency: 3
- httpApi: '*'
custom:
secrets: ${file(secrets.json)}
nuxt.config.ts
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const deps = require("./package.json").dependencies;
export default defineNuxtConfig({
css: ['@/assets/css/input.css'],
modules: [
'@nuxt/ui',
'@nuxtjs/tailwindcss',
],
builder: 'webpack',
nitro: {
preset: 'aws-lambda',
serveStatic: true,
prerender: {
crawlLinks: true,
}
},
webpack: {
plugins: [
],
}
})
有人有这方面的经验吗?它成功部署,但是在 cloudwatch 中访问带有以下错误的 URL 时,我不断收到内部服务器错误:
entrypoint requires the handler name to be the first argument