brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.15k stars 365 forks source link

Cannot execute binary file #1456

Closed Pr3d4dor closed 1 year ago

Pr3d4dor commented 1 year ago

Description:

Recently we updated our backend to bref v2, using arm images, but we are getting this error:

/opt/bootstrap: line 15: /opt/bin/php: cannot execute binary file 

Did we do something wrong?

serverless.yml

service: our-app

provider:
  name: aws
  runtime: provided.al2
  lambdaHashingVersion: 20201221
  vpc:
    securityGroupIds:
      - ${env:VPC_SECURITY_GROUP_ID}
    subnetIds:
      - ${env:VPC_SUBNET_ID_1}
      - ${env:VPC_SUBNET_ID_2}
      - ${env:VPC_SUBNET_ID_3}
  environment:
    ...
  deploymentMethod: direct
  iam:
    role:
      statements:
        # Allows our code to interact with SQS
        - Effect: Allow
          Action: [sqs:SendMessage, sqs:DeleteMessage]
          Resource: !GetAtt AlertQueue.Arn
        # Allow Lambda to read and write files in the S3 bucket
        - Effect: Allow
          Action: s3:*
          Resource:
            - "${env:S3_BUCKET_ARN}" # the storage bucket
            - "${env:S3_BUCKET_ARN}/*" # and everything inside

package:
  # Directories to exclude from deployment
  patterns:
    - "!.gitignore"
    - "!.env"
    - "!.env.example"
    - "!bitbucket-pipelines.yml"
    - "!README.md"
    - "!serverless.yml"
    - "!node_modules/**"
    - "!public/storage"
    - "!resources/assets/**"
    - "!tests/**"
    - "storage/framework/views/**"

functions:
  # This function runs the Laravel website/API
  web:
    handler: public/index.php
    timeout: ${env:WEB_LAMBDA_TIMEOUT}
    reservedConcurrency: ${env:WEB_LAMBDA_RESERVED_CONCURRENCY} # Limit of concurrent lambdas executing
    layers:
      - ${bref:layer.arm-php-82-fpm}
    events:
      - schedule:
          rate: rate(8 minutes)
          input:
            warmer: true
      - alb:
          listenerArn: ${env:ALB_LISTENER_ARN}
          priority: 1
          conditions:
            path: /

  # This function lets us run artisan commands in Lambda
  artisan:
    handler: artisan
    timeout: 240 # in seconds
    layers:
      - ${bref:layer.arm-php-82} # PHP
      - ${bref:layer.console} # The "console" layer

  # This function lets us run artisan our Scheduled Commands in Lambda
  cron:
    handler: artisan
    layers:
      - ${bref:layer.arm-php-82} # PHP runtime
      - ${bref:layer.console} # Console layer
    events:
      ...

  # This function lets us run artisan our Jobs in Lambda
  worker:
    handler: Bref\LaravelBridge\Queue\QueueHandler
    timeout: 28
    layers:
      - ${bref:layer.arm-php-82}
    events:
      # Declares that our worker is triggered by jobs in SQS
      - sqs:
          arn: !GetAtt AlertQueue.Arn
          # If you create the queue manually, the line above could be:
          # arn: 'arn:aws:sqs:us-east-1:1234567890:my_sqs_queue'
          # Only 1 item at a time to simplify error handling
          batchSize: 1
          maximumBatchingWindow: 60

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

resources:
  Resources:
    # The SQS queue
    AlertQueue:
      Type: AWS::SQS::Queue
      Properties:
        RedrivePolicy:
          maxReceiveCount: 5 # jobs will be retried up to 5 times
          # Failed jobs (after the retries) will be moved to the other queue for storage
          deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn

    # Failed jobs will go into that SQS queue to be stored, until a developer looks at these errors
    DeadLetterQueue:
      Type: AWS::SQS::Queue
      Properties:
        MessageRetentionPeriod: 1209600 # maximum retention: 14 days

How to reproduce:

Use an arm image.

mnapoli commented 1 year ago

Thanks for the report!

It seems (from a quick look) that you didn't set the architecture field in serverless.yml?

Pr3d4dor commented 1 year ago

@mnapoli Thanks for the response, we did not set it. I will try it now. Maybe I misread something in the docs (that using layers, the architecture field is not needed).

Warning: the example above uses the new runtime: php-xx syntax introduced above. If you set layers instead, you will need to update them to reference ARM layers:
Pr3d4dor commented 1 year ago

@mnapoli It worked, thanks!

I will close the issue now.

mnapoli commented 1 year ago

Thanks for the feedback, I have pushed https://github.com/brefphp/bref/commit/651523ecfef982ba5d2299f5580b39b400c1a617 to improve the guide!