我正在使用 SAM 编写无服务器应用程序。我创建了一个配置文件夹来保存一些表信息和一些其他信息。然后我将它加载到我的 app.js 中。
当我使用 SAM deploy 在本地部署 app.js 时,我观察到配置文件夹将不包括在内。你介意告诉我如何在 .aws-sam\build 文件夹的最终构建文件夹中添加配置文件夹吗?
我的 Yaml 文件
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample SAM Template for test
Globals:
Function:
Timeout: 120
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs10.x
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
此外,当我在调试模式下运行项目时,我收到此错误:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '../config/config.js'"
}
我加载js文件如下:
"use strict";
let response;
const AWS = require('aws-sdk');
const config = require('../config/config.js');