简体   繁体   English

bref.sh php 容器,用于带有 Neos CMS 的 AWS Lambda

[英]bref.sh php container for AWS Lambda with Neos CMS

I'm struggling to get Neos (a php based cms) to run in a docker container for AWS Lambda.我正在努力让 Neos(基于 php 的 cms)在 AWS Lambda 的 docker 容器中运行。 I guess I have somewhere a misunderstanding and hope anyone can help.我想我在某个地方有误会,希望有人能提供帮助。

What I did so far:到目前为止我做了什么:

  1. I adjusted Neos so that all cache files will be written to the tmp folder我调整了 Neos,以便将所有缓存文件写入 tmp 文件夹
  2. I added the bref and extra-php-extensions package to composer.json我将 bref 和 extra-php-extensions package 添加到 composer.json
  3. I created a docker file, quite simple as shown by Mattheu Naploli's blog article: https://mnapoli.fr/aws-lambda-php-docker-containers/我创建了一个 docker 文件,非常简单,如 Mattheu Naploli 的博客文章所示: https://mnapoli.fr/aws-lambda-php-docker-containers/
  4. I have created a cloudformation template to use sam local start-api我创建了一个 cloudformation 模板来使用sam local start-api

Dockerfile: Dockerfile:

FROM bref/php-74-fpm

COPY . /var/task

# Start Bref's runtime client
CMD _HANDLER=Web/index.php /opt/bootstrap

template.yml模板.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  neos-demo-lambda

  Sample SAM Template for neos-demo-lambda

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  Neos:
    Type: AWS::Serverless::Function
    Properties:
      Description: Show neos demo
      PackageType: Image
      ImageUri: neos7.demo.lambda.php74:latest
      #Handler: "Web/index.php /opt/bootstrap"
      #Handler: "Web/index.php"
      MemorySize: 1024
      Timeout: 360
      Environment:
        Variables:
          FLOW_CONTEXT: 'Production'
          FLOW_PATH_TEMPORARY_BASE: '/tmp/neos'
          FLOW_PATH_DATA_BASE: '/tmp/Data'
          BREF_AUTOLOAD_PATH: '/var/task/Packages/Libraries/autoload.php'
          AWS_S3_BUCKET_STORAGE: 'neos-lambda-demo-private'
          AWS_S3_BUCKET_TARGET: 'neos-lambda-demo-public'
          AWS_CLOUDFRONT_BASE_URI: ''
          AWS_REDIS_HOST: ''

      Events:
        htmlHttpApi:
          Type: HttpApi
          TimeoutInMillis: 28000

    Metadata:
      DockerTag: neos7.lambda.demo
      DockerContext: ./Web/index.php
      Dockerfile: Dockerfile

Response of sam local start-api : sam local start-api的响应:

entrypoint requires the handler name to be the first argument
time="2021-04-14T22:11:48.093" level=error msg="Init failed" InvokeID= error="Runtime exited with error: exit status 142"
time="2021-04-14T22:11:48.093" level=error msg="INIT DONE failed: Runtime.ExitError"
Invalid lambda response received: Lambda response must be valid json
2021-04-15 00:11:48 127.0.0.1 - - [15/Apr/2021 00:11:48] "GET / HTTP/1.1" 502 -

What I don't understand, I'd expect that there is always a valid json returned, even though the php delivers a 5xx error.我不明白的是,我希望始终返回有效的 json,即使 php 提供 5xx 错误。 I'm lost... even though this wouldn't be the case, how can I debug the issue?我迷路了......即使情况并非如此,我该如何调试问题?

In the end, I have to create my own docker image as Neos is too big to use the bref layers and I need quite some php extensions.最后,我必须创建自己的 docker 图像,因为 Neos 太大而无法使用 bref 层,我需要相当多的 php 扩展。 If I could understand the current issue, I can work through this and provide a working container for everyone.如果我能理解当前的问题,我可以解决这个问题并为每个人提供一个工作容器。

I have a few more questions, in this scenario, were I have a web application and use a container, do I have to install the bref packages with composer?我还有几个问题,在这种情况下,我是否有 web 应用程序并使用容器,我是否必须使用 composer 安装 bref 包? That wasn't clear in the blog post.这在博客文章中并不清楚。 Also do I have to set the Handler in serverless/sam and if so, which would be the correct string, given that Web/index.php is the path in Neos?我还必须在 serverless/sam 中设置 Handler,如果是这样,这将是正确的字符串,因为Web/index.php是 Neos 中的路径?

In general, Neos would work awesome in AWS.总的来说,Neos 在 AWS 中会非常出色。 My setup would be:我的设置是:

  1. CloudFront with behaviors for static files from S3 and everything else to lambda CloudFront 具有 static 文件的行为,从 S3 和其他所有文件到 lambda
  2. Redis to store cache files from Neos Redis 用于存储来自 Neos 的缓存文件
  3. ElasticSearch for website search and improved performance on huge sites ElasticSearch 用于网站搜索并提高大型网站的性能

As soon as this is working, I'll publish all information for free for the Neos community to get this working.一旦这工作正常,我将免费为 Neos 社区发布所有信息以使其正常工作。

Hope someone can help...希望有人可以帮助...

Thank you!谢谢!

Could you try this:你能试试这个:

FROM bref/php-74-fpm

# Include any extension you want, for example:
#COPY --from=bref/extra-gd-php-74:0.9.5 /opt /opt

ADD . $LAMBDA_TASK_ROOT

CMD [ "index.php" ]

The format has been simplified since the article (see https://gist.github.com/mnapoli/f911a50c7aab77690e6cdde157812265 ).自文章以来,格式已被简化(参见https://gist.github.com/mnapoli/f911a50c7aab77690e6cdde157812265 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM