Skip to content

Latest commit

 

History

History
180 lines (106 loc) · 3.71 KB

File metadata and controls

180 lines (106 loc) · 3.71 KB

Installation


To use our beloved PHP with Lambda from the command line, we need to use the Bref project's PHP plugin for the Serverless Framework.

The Serverless Framework is free and open source software written in NodeJS to develop and deploy serverless apps to (among others) the AWS serverless platform.



(1) Install NodeJS


See the NodeJS website for info.



(2) Install the Serverless Framework


Install the Serverless Framework (getting-started docs):

npm install -g serverless


(3) Set up your IAM user in your AWS Console


  • log into your AWS console

  • go to the IAM dashboard

  • in the left menu bar, click "Users". Add a new user. I suggest this name: "lambda_functions_with_serverless_framework"

  • attach the policy "AdministratorAccess" --> do NOT use this user in production!

  • do not assign console management access. Programmatic access only

  • keep the window that has your Access Keys open for reference



(4) Create your local AWS credentials file


AWS needs to authenticate you. And, AWS needs to know what account you want to use.

Since you are going to deploy your Lambda function from your local CLI, your credentials will be stored your your local ".aws/credentials" file.

Run this command from your command line:

serverless config credentials --provider aws --key <access key> --secret <secret>

The file ".aws/credentials" should now exist, and contain your AWS keys.



(5) Create your S3 Bucket for Lambda Functions


I recommend that you dedicate an S3 bucket for your Lambda functions:

  • reduces the clutter of your "root" S3 listing in the console
  • helps visually to find folders that are for your Lambda function
  • makes it easy to assign an AWS region to your folder.

Your Lambda function must be in the same AWS region as your S3 bucket.


  • go to your S3 dashboard.

  • at the main (right) area, click the "Create bucket" button at the top

  • name your bucket name something like "lambda-functions-with-serverless-framework-"

  • assign your new bucket to an AWS region

  • keep this window open for later reference.



(6) Clone this repo on your local computer


  • click the green "Code" button at the top this repo's "home" page

  • use your favourite way of cloning



(7) Run "composer install"


This is for:

  • the Lambda function, which is written in PHP
  • the Bref PHP plugin for the Serverless Framework
composer install


(8) Modify the serverless.yml file


The "serverless.yml" is for the Serverless Framework.

This file will not work out-of-the-box. You need to modify it.

To modify the serverless.yml file, please follow the inline comments.



(9) Modify the src/Handler.php, and/or other src/* files


The src/Handler.php, or src/Form.php, or other src/*.php file, may have vars for you to set correctly.

Please follow the inline comments.



(10) Deploy your code to the AWS serverless platform


At your command line, run:

serverless deploy


(11) Look at your AWS Console


See your new Lambda function in the AWS Console:

  • Lambda dashboard
  • S3 dashboard
  • CloudFormation dashboard
  • API Gateway dashboard
  • IAM dashboard
  • sometimes the SES, SNS, and other dashboards