Import in node js file for aws lambda function is not working when I deployed it with serverless
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- aws, javascript, node.js
Línea de trabajo
Empieza comparando app.js, app_home.js, serverless.yml y package.json, y después despliega la versión con el import para inspeccionar los logs de AWS Lambda en busca del fallo. El issue no incluye app_home.js ni un mensaje de error, así que confirma el import que falla y el comportamiento del despliegue antes de hacer un cambio; la tarea está terminada cuando el endpoint POST de Slack funciona con los archivos separados.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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"
}
}
- Lenguaje dominante
- JavaScript
- Estrellas
- 11.5k
- Forks
- 4.4k
- Merge medio
- 2 h 55 min
- PR fusionados (30 d)
- 3
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de serverless/examples
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
serverless/examples#404 ·
-
ENOTDIR error on starter project Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
serverless/examples#809 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 30/100
serverless/examples#793 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
serverless/examples#784 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
serverless/examples#782 ·
Todos los issues de serverless/examples
Issues similares
-
Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Automattic/safe-publish#594 ·
-
内部文件键(绝对路径的 base64)泄漏到界面标签 Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
dream-num/dsh-univer-office#104 ·
-
comp/dashboard invalid P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
NousResearch/hermes-agent#121143 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
avniproject/avni-webapp#1811 ·
-
area/auroraboot area/webui bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100