简体   繁体   English

如何在aws lambda中部署在zend expressive中创建的API?

[英]How can Ideploying APIs created in zend expressive in aws lambda?

I have created a Zend expressive application that basically exposes a few APIs.我创建了一个 Zend 富有表现力的应用程序,它基本上公开了一些 API。 I want to deploy this now to AWS Lambda.我现在想将它部署到 AWS Lambda。 What is the best way to refactor the code quickly and easily (or is there any other alternatives) to deploy it?快速轻松地重构代码(或有其他替代方案)以部署它的最佳方法是什么? I am fairly new in AWS.我是 AWS 的新手。

I assume that you have found the answer already since the question is more than five months old.我假设您已经找到了答案,因为这个问题已经超过五个月了。 But I am posting what I have found in my recent research in the same criteria.但我将我在最近的研究中发现的内容以相同的标准发布。 Please note that you need to have at least some idea on how AWS IAM, Lambda, API Gateway in order to follow the steps I have described below.请注意,您至少需要对 AWS IAM、Lambda、API 网关的方式有所了解,才能按照我在下面描述的步骤进行操作。 Also please note that I have only deployed the liminas/mezzio skeleton app during this research and you'll need much more work to deploy a real app because it might need database & storage support in the AWS environment which might require to adapt your application accordingly.另请注意,在这项研究期间,我只部署了 liminas/mezzio 框架应用程序,您需要做更多的工作来部署真正的应用程序,因为它可能需要 AWS 环境中的数据库和存储支持,这可能需要相应地调整您的应用程序.

PHP application cab be executed using the support for custom runtimes in AWS. PHP 应用程序可以使用 AWS 中的自定义运行时支持来执行。 You could check this AWS blog article on how to get it done but it doesn't cover any specific PHP framework.您可以查看这篇AWS 博客文章,了解如何完成它,但它不涵盖任何特定的 PHP 框架。

Then I have found this project which provides all then necessary tools for running a PHP application in serverless environment.然后我发现这个项目提供了在无服务器环境中运行 PHP 应用程序所需的所有工具。 You could go through their documentation to get an understanding how things work.您可以通过他们的文档 go 了解事情是如何工作的。

In order to get the liminas/mezzio (new name of the zend expressive project) skeltopn app working, I have followed the laravel tutorial given in the bref documentation.为了让 liminas/mezzio(zend 表达项目的新名称)skeltopn 应用程序正常工作,我遵循了 bref 文档中给出的laravel 教程 First I installed bref package using首先我安装了 bref package 使用

composer require bref/bref

Then I have created the serverless.yml file in the root folder of the project according to the documentation and made few tweaks in it and it looked like as follows.然后我根据文档在项目的根文件夹中创建了 serverless.yml 文件,并对其进行了一些调整,如下所示。

service: myapp-serverless

provider:
     name: aws
     region: eu-west-1 # Change according to the AWS region you use
     runtime: provided

plugins:
     - ./vendor/bref/bref

package:
     exclude:
         - node_modules/**
         - data/**
         - test/**

functions:
     api:
          handler: public/index.php
          timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
          memorySize: 512 # Memory size for the AWS lambda function. Default is 1024MB
          layers:
               - ${bref:layer.php-73-fpm}
          events:
               -   http: 'ANY /'
               -   http: 'ANY /{proxy+}'

Then I followed the deployment guidelines given in the bref documentation which is to use serverless framework for the deployment of the app.然后我遵循了 bref 文档中给出的部署指南,即使用无服务器框架来部署应用程序。 You can check here how to install serverless framework on your system and here to see how it need to be configured.您可以在此处查看如何在您的系统上安装无服务器框架,并在此处查看需要如何配置它。

To install servreless I have used npm install -g serverless要安装无服务器,我使用npm install -g serverless

To configure the tool I have used serverless config credentials --provider aws --key <key> --secret <secret> .要配置该工具,我使用了serverless config credentials --provider aws --key <key> --secret <secret> Please note that this key used here needs Administrator Access to the AWS environment.请注意,此处使用的此密钥需要管理员访问 AWS 环境。

Then serverless deploy command will deploy your application to the AWS enviroment.然后serverless deploy命令会将您的应用程序部署到 AWS 环境。

The result of the above command will give you an API gateway endpoint with which you application/api will work.上述命令的结果将为您提供一个 API 网关端点,您的应用程序/api 将使用该端点。 This is intended as a starting point for a PHP serverless application and there might be lots of other works needed to be done to get an real application working there.这旨在作为 PHP 无服务器应用程序的起点,并且可能需要完成许多其他工作才能让真正的应用程序在那里工作。

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

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