Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Import in node js file for aws lambda function is not working when I deployed it with serverless

Đang mở
#646 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
aws, javascript, node.js
Lĩnh vực
backend, cloud

Hướng nghiên cứu

Bắt đầu bằng cách so sánh app.js, app_home.js, serverless.yml và package.json, sau đó deploy phiên bản có import và kiểm tra log AWS Lambda để tìm lỗi. Issue không bao gồm app_home.js hoặc thông báo lỗi, vì vậy hãy xác nhận import bị lỗi và hành vi deployment trước khi thay đổi; hoàn tất khi endpoint POST của Slack hoạt động với các file đã được tách.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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"
  }
}

Ngôn ngữ chính
JavaScript
Star
11.5k
Fork
4.4k
Merge trung bình
2 giờ 55 phút
Pull request đã merge (30 ngày)
3

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của serverless/examples

Tất cả issue của serverless/examples

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.