Package: cdk-serverless-lamp
Welcome to cdk-serverless-lampcdk-serverless-lampis a JSII construct library for AWS CDK that allows you to deploy theNew Serverless LAMP Stackrunning PHP Laravel Apps by specifying the locallaraveldirectory.By deploying theServerlessLaravelandDatabaseCluster, the following resources will be created:Amazon API Gateway HTTP APIAWS Lambda custom runtime withBref runtimesupportAmazon Aurora for MySQL database cluster with RDS proxy enabledHowtoCreate a new Laravel project with AWS CDK$mkdirserverless-lamp&&cdserverless-lamp# create cdk and codebase directories for AWS CDK and Laravel project$mkdircdkcodebase# create the new Laravel project with docker$dockerrun--rm-ti\--volume$PWD:/app\composercreate-project--prefer-distlaravel/laravel./codebase# install bref/bref and bref/laravel-bridge in the vendor$cdcodebase
$dockerrun--rm-ti\--volume$PWD:/app\composerrequirebref/brefbref/laravel-bridge# initialize the AWS CDK project$cd../cdk
$cdkinit-ltypescript# install the cdk-severless-lamp npm module$yarnaddcdk-serverless-lampNow your directories should look like this:.
├── cdk
└── codebasewherecdkis for the AWS CDK andcodebasefor Laravel project.AWS CDK sampleBuilding your serverless Laravel withServerlessLaravelconstruct:Update./cdk/lib/cdk-stack.tsimport*ascdkfrom'@aws-cdk/core';import*aspathfrom'path';import{ServerlessLaravel}from'cdk-serverless-lamp';exportclassCdkStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);newServerlessLaravel(this,'ServerlessLaravel',{brefLayerVersion:'arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12',laravelPath:path.join(__dirname,'../../codebase'),});}}deploy the CDK stack:# see the difference before the deployment$cdkdiff# deploy it$cdkdeployOn deploy complete, the API Gateway URL will be returned in the Output. Click the URL and you will see the Laravel landing page:Amazon Aurora supportUseDatabaseClusterto create the your database cluster:import*ascdkfrom'@aws-cdk/core';import{InstanceType,Vpc}from'@aws-cdk/aws-ec2';import*aspathfrom'path';import{ServerlessLaravel,DatabaseCluster}from'cdk-serverless-lamp';exportclassCdkStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);constvpc=newVpc(this,'Vpc',{maxAzs:3,natGateways:1})//theDatabaseClustersharingthesamevpcwiththeServerlessLaravelconstdb=newDatabaseCluster(this,'DatabaseCluster',{vpc,instanceType:newInstanceType('t3.small'),rdsProxy:true,})//theServerlessLaravelnewServerlessLaravel(this,'ServerlessLaravel',{brefLayerVersion:'arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12',laravelPath:path.join(__dirname,'../../codebase'),vpc,databaseConfig:{writerEndpoint:db.rdsProxy!.endpoint,},});}}Local DevelopmentCreatedocker-compose.ymlwith the following content:version: "3.5"
services:
  web:
    image: bref/fpm-dev-gateway
    ports:
      - "8000:80"
    volumes:
      - ./laravel:/var/task
    depends_on:
      - php
    environment:
      HANDLER: public/index.php
  php:
    image: bref/php-74-fpm-dev
    volumes:
      - ./laravel:/var/taskand run this commanddocker-compose up -dand now you can accesshttp://localhost:8000.(more information can be found inbref documentation)