简体   繁体   中英

How can Ideploying APIs created in zend expressive in aws lambda?

I have created a Zend expressive application that basically exposes a few APIs. I want to deploy this now to 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.

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. 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.

PHP application cab be executed using the support for custom runtimes in AWS. You could check this AWS blog article on how to get it done but it doesn't cover any specific PHP framework.

Then I have found this project which provides all then necessary tools for running a PHP application in serverless environment. You could go through their documentation to get an understanding how things work.

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. First I installed bref package using

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.

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. 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

To configure the tool I have used serverless config credentials --provider aws --key <key> --secret <secret> . Please note that this key used here needs Administrator Access to the AWS environment.

Then serverless deploy command will deploy your application to the AWS enviroment.

The result of the above command will give you an API gateway endpoint with which you application/api will work. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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