【问题标题】:Problem with fs-extra while deploying python using serverless使用无服务器部署 python 时 fs-extra 出现问题
【发布时间】:2021-01-26 02:30:06
【问题描述】:

我不是使用npmbitbucket-pipelines 的专家,但我想在Bitbucket 上创建一个管道,以使用serverless 将我的python(烧瓶)项目部署到AWS Lambda。它正在本地部署,但是当我使用 Bitbucket 管道运行它时,会发生这种情况:

错误:找不到模块“/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js”。请验证 package.json 是否有有效的“main”条目

这是我的代码:

bitbucket-pipelines.yml

image: node:14.13.1-alpine3.10

pipelines:
  branches:
    master:
      - step:
          caches:
            - node
          script:
            - apk add python3
            - npm install
            - npm install -g serverless
            - serverless config credentials --stage dev --provider aws --key ${AWS_DEV_LAMBDA_KEY} --secret ${AWS_DEV_LAMBDA_SECRET}
            - serverless deploy --stage dev

serverless.yml

service: serverless-flask

plugins:
  - serverless-python-requirements
  - serverless-wsgi

custom:
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux

provider:
  name: aws
  runtime: python3.8
  stage: dev
  region: us-west-2

functions:
  app:
    handler: wsgi.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'
  alert:
    handler: alerts.run
    events:
      - schedule: rate(1 day)

package:
    exclude:
      - .venv/**
      - venv/**
      - node_modules/**
      - bitbucket-pipelines.yml

我该如何解决这个问题?

【问题讨论】:

  • 你是怎么解决这个问题的?尝试通过 bitbucket 部署时遇到相同的错误

标签: node.js aws-lambda serverless bitbucket-pipelines


【解决方案1】:

我遇到了同样的问题,通过(重新)安装 fs-extra 解决了这个问题

npm install fs-extra

【讨论】:

    【解决方案2】:

    在相同情况下帮助我的是:

    1. 已删除/node_modules 文件夹
    2. 在服务文件夹内运行npm install
    3. 运行serverless deploy

    【讨论】:

      猜你喜欢
      • 2022-12-09
      • 2020-01-01
      • 1970-01-01
      • 2021-10-07
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多