Import in node js file for aws lambda function is not working when I deployed it with serverless
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- aws, javascript, node.js
调研方向
先比较 app.js、app_home.js、serverless.yml 和 package.json,然后部署包含 import 的版本并检查 AWS Lambda 日志以查找故障。该 issue 不包含 app_home.js 或错误消息,因此在进行更改前确认失败的 import 和部署行为;当 Slack POST 端点使用拆分后的文件正常工作时即表示完成。
由索引模型根据 Issue 内容生成。
描述
Hi,
So I was trying to build a slack app and deploy it to aws. I built the app and it works fine but when I try and create other js files to import them in my main, the aws post url doesn't work.
The structure of my project(app) is:
Slack-app:
-------------- app.js
-------------- app_home.js
-------------- package.json
-------------- package-lock.json
-------------- serverless.yml
..... The others are node_modules, .serverless etc.
So basically, without the import of app_home.js, the code works when deployed to aws lambda. On the slack app, it sends a message back when you type in hello. But when I add an import, the whole thing, doesn't work.
This works:
"use strict";
const { App, AwsLambdaReceiver, WorkflowStep } = require('@slack/bolt');
// Initialize your custom receiver
const awsLambdaReceiver = new AwsLambdaReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
});
// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
receiver: awsLambdaReceiver,
// The `processBeforeResponse` option is required for all FaaS environments.
// It allows Bolt methods (e.g. `app.message`) to handle a Slack request
// before the Bolt framework responds to the request (e.g. `ack()`). This is
// important because FaaS immediately terminate handlers after the response.
processBeforeResponse: true
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// say() sends a message to the channel where the event was triggered
await say({
text: `Hey there <@${message.user}>! \n Have any questions or concerns, Please contact the IT team.`
});
});
// Handle the Lambda function event
module.exports.handler = async (event, context, callback) => {
const handler = await awsLambdaReceiver.start();
return handler(event, context, callback);
}
Where as, this doesn't work at all:
"use strict";
const { App, AwsLambdaReceiver, WorkflowStep } = require('@slack/bolt');
// THIS IS THE LINE THAT I CHANGED FROM THE PREVIOUS CODE
const app_home = require('./app_home')
// Initialize your custom receiver
const awsLambdaReceiver = new AwsLambdaReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
});
// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
receiver: awsLambdaReceiver,
// The `processBeforeResponse` option is required for all FaaS environments.
// It allows Bolt methods (e.g. `app.message`) to handle a Slack request
// before the Bolt framework responds to the request (e.g. `ack()`). This is
// important because FaaS immediately terminate handlers after the response.
processBeforeResponse: true
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// say() sends a message to the channel where the event was triggered
await say({
text: `Hey there <@${message.user}>! \n Have any questions or concerns, Please contact the IT team.`
});
});
// Handle the Lambda function event
module.exports.handler = async (event, context, callback) => {
const handler = await awsLambdaReceiver.start();
return handler(event, context, callback);
}
So, I was just working, if it is a deployment issue?
My code for serverless is:
service: slack-app-bolt-js-forto
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
profile: default
timeout: 5
stage: ${opt:stage, 'dev'}
memorySize: 512
environment:
SLACK_SIGNING_SECRET: ${env:SLACK_SIGNING_SECRET}
SLACK_BOT_TOKEN: ${env:SLACK_BOT_TOKEN}
functions:
slack:
handler: app.handler
memorySize: 1536
timeout: 30
events:
- http:
path: slack/events
method: post
plugins:
- serverless-offline
package.json looks like this
{
"name": "bolt-js-getting-started-app",
"version": "2.0.0",
"description": "Getting Started ⚡️ Bolt for JavaScript",
"main": "app.js",
"scripts": {
"ngrok": "ngrok http 3000",
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "MIT",
"dependencies": {
"@slack/bolt": "^3.6.0",
"axios": "^0.21.4"
},
"devDependencies": {
"serverless": "^2.59.0",
"serverless-offline": "^8.2.0"
}
}
- 主要语言
- JavaScript
- 星标
- 11.5k
- 派生
- 4.4k
- 平均合并
- 2 小时 55 分钟
- 30 天内合并 PR
- 3
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
serverless/examples 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 62/100
serverless/examples#404 ·
-
难度 3/5 1-2 天 新手友好度 35/100
serverless/examples#809 ·
-
难度 2/5 1-3 小时 新手友好度 30/100
serverless/examples#793 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 20/100
serverless/examples#784 ·
-
难度 4/5 3-5 天 新手友好度 25/100
serverless/examples#782 ·
查看 serverless/examples 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
mksglu/context-mode#1200 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
neondatabase/website#5944 ·
-
module: core
难度 2/5 1-3 小时 新手友好度 75/100
bigbluebutton/bigbluebutton#25849 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
jaegertracing/jaeger-ui#4506 ·