How to add a custom folder and file via YAML in Serverless app

被刻印的时光 ゝ 提交于 2019-12-11 12:45:59

问题


I am writing a serverless app by using SAM. I created a config folder to keep some table information and some other info. then I load it in my app.js.

when I deploy the app.js locally by using SAM deploy, I observe that the config folder will not include. would you mind advise me how to add config folder in final build folder in .aws-sam\build folder?

my Yaml file

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

Also when I run the project in debug mode I am getting this error:

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module '../config/config.js'"
}

I load the js file as below:

"use strict";

let response;
const AWS = require('aws-sdk');
const config = require('../config/config.js');

来源:https://stackoverflow.com/questions/58502648/how-to-add-a-custom-folder-and-file-via-yaml-in-serverless-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!