【问题标题】:An error occured: ArtisanLambdaFunction - Unzipped size must be smaller than 220606645 bytes (Service: Lambda, Status Code: 4000发生错误:ArtisanLambdaFunction - 解压后的大小必须小于 220606645 字节(服务:Lambda,状态码:4000
【发布时间】:2021-10-16 16:52:54
【问题描述】:

我试图使用 Bref 将我的 Laravel 应用程序部署到 AWS Lambda。 我试图排除几乎所有的图像、视频,但我仍然得到了

Serverless Error ----------------------------------------
An error occurred: ArtisanLambdaFunction - Resource handler returned message: "Unzipped size must be smaller than 235311048 bytes (Service: Lambda, Status Code: 400 ...

我的 serverless.yml 文件是

service: my-laravel-application

provider:
    name: aws
    # The AWS region in which to deploy (us-east-1 is the default)
    region: eu-west-1
    # The stage of the application, e.g. dev, production, staging… ('dev' is the default)
    stage: dev
    runtime: provided.al2

package:
    individually: true
    # Directories to exclude from deployment
    exclude:
        - node_modules/**
        - public/storage/**
        - resources/assets/**
        - storage/**
        - tests/**
        - public/images/**
        - public/uploads/**
        - public/videos/**

functions:
    # This function runs the Laravel website/API
    web:
        handler: public/index.php
        timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
        layers:
            - ${bref:layer.php-74-fpm}
        events:
            -   httpApi: '*'
    # This function lets us run artisan commands in Lambda
    artisan:
        handler: artisan
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-74} # PHP
            - ${bref:layer.console} # The "console" layer

 plugins:  
    # We need to include the Bref plugin
    - ./vendor/bref/bref 

我试图从 zip 中排除几乎所有资产。不过,我得到了同样的错误。 压缩时,我的应用程序的总大小仅为 119.4 MB。

【问题讨论】:

    标签: laravel aws-lambda serverless bref


    【解决方案1】:

    我可以通过将所有公共资产添加到排除列表来解决此问题,从而将 zip 文件的大小减少到 43 MB。

    解压时,解压后总大小小于220606645字节

    那么,

    1. 上传所有公用文件夹文件和文件夹到S3
    2. 在环境中添加 ASSET_URL
    3. 在我们尝试从 S3 访问文件时使用asset() 函数

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2021-04-30
      • 1970-01-01
      • 2021-07-18
      • 2021-09-22
      • 2021-11-16
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      相关资源
      最近更新 更多