В настоящее время я пытаюсь развернуть лямбда-функцию AWS, используя сервер. Я могу получить функцию для правильного развертывания и ответа, если не включаю внешние модули, однако, как только я попытаюсь включить dynogels и Joi:
const dynogels = require("dynogels");
const Joi = require("@hapi/joi");
, команда serverless deploy
не пройдет «упаковка внешних модулей»
Полный вывод при не , включая внешние модули:
❯ sls deploy
{ addHandler: './addHandler.js' }
Serverless: Bundling with Webpack...
1 module
Serverless: No external modules needed
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service game-data-service.zip file to S3 (1.9 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: game-data-service
stage: dev
region: ap-southeast-2
stack: game-data-service-dev
resources: 11
api keys:
None
endpoints:
POST - XXXXXXXXXXX/endpoint
functions:
addData: game-data-service-dev-addData
layers:
None
Serverless: Updated basepath mapping.
Serverless Domain Manager Summary
Domain Name
XXXXXXXXXXX.com
Distribution Domain Name
Target Domain: XXXXXXXXXXX
Hosted Zone Id: XXXXXXXXXXX
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.
Полный вывод при включении внешних модулей:
❯ sls deploy
{ addHandler: './addHandler.js' }
Serverless: Bundling with Webpack...
3 modules
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: dynogels@^9.1.0, @hapi/joi@^17.1.0
Пакеты установлены. Я не понимаю, почему это не развертывается. Есть ли способ увидеть некоторые ошибки при развертывании? --verbose
, кажется, не дает много дополнительной информации. Спасибо за вашу помощь!
Редактировать serverless.yml
service: game-data-service
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: ap-southeast-2
environment:
SERVICE_NAME: ${self:service}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchGetItem
Resource: "arn:aws:dynamodb:ap-southeast-2:*:*"
- Effect: Allow
Action:
- codepipeline:StartPipelineExecution
Resource: "arn:aws:codepipeline:ap-southeast-2:*:*"
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
Resource: "arn:aws:s3:::XXXXXXXXXXX-assets-bucket/*"
plugins:
- serverless-domain-manager
- serverless-webpack
custom:
stage: ${opt:stage, self:provider.stage}
admin_arn: XXXXXXXXXX
user_arn: XXXXXXXXXXX
domains:
prod: XXXXXXXXXXX.com
staging: XXXXXXXXXXX.com
dev: XXXXXXXXXXX.com
webpack:
webpackConfig: "webpack.config.js"
includeModules: true # Node modules configuration for packaging
packagePath: "../package.json"
customDomain:
basePath: gameData
domainName: ${self:custom.domains.${self:custom.stage}}
stage: "${self:custom.stage}"
createRoute53Record: true
##############################################################
# Functions
##############################################################
functions:
addData:
handler: addHandler.hello
events:
- http: POST add
webpack.config.js
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
var path = require("path");
function resolve(dir) {
return path.join(__dirname, dir);
}
console.log(slsw.lib.entries);
module.exports = {
entry: slsw.lib.entries,
target: "node",
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
externals: [nodeExternals()],
resolve: {
alias: {
"@": resolve("../lib"),
"=": resolve("../db")
}
},
optimization: {
minimize: false
},
mode: slsw.lib.webpack.isLocal ? "development" : "production",
stats: "minimal"
};
addHandler.js
"use strict";
import { success, failure } from "@/response";
// import schema from "=/schema";
// import gameSchema from "=/gameSchema";
// const dynogels = require("dynogels");
// const Joi = require("@hapi/joi");
const cowsay = require("cowsay");
export const hello = (event, context, callback) => {
console.log("Running ADD");
console.log(cowsay.say({ text: "Mooodule" }));
const body = JSON.parse(event.body);
const table = body["table"];
const data = body["data"];
if (body["table"] == null) {
callback(
null,
failure({
error: "You must provide the table name in the body"
})
);
}
console.log(`Body recieved for table ${table}:`, data);
callback(null, success({ message: `Data added to ${table}` }));
// try {
// gameSchema[event.pathParameters.table].create(body, (err, res) => {
// if (err) {
// callback(null, failure({ error: err }));
// return;
// }
// callback(null, success(res));
// });
// callback(null, success(res));
// } catch (err) {
// callback(null, failure({ error: err }));
// return;
// }
};