cdk-serverless-lamp


Namecdk-serverless-lamp JSON
Version 1.4.50 PyPI version JSON
download
home_pagehttps://github.com/aws-samples/cdk-serverless-lamp.git
SummaryA JSII construct lib to build AWS Serverless LAMP with AWS CDK
upload_time2021-09-27 16:05:03
maintainer
docs_urlNone
authorPahud Hsieh<hunhsieh@amazon.com>
requires_python>=3.6
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![NPM version](https://badge.fury.io/js/cdk-serverless-lamp.svg)](https://badge.fury.io/js/cdk-serverless-lamp)
[![PyPI version](https://badge.fury.io/py/cdk-serverless-lamp.svg)](https://badge.fury.io/py/cdk-serverless-lamp)
![Build](https://github.com/aws-samples/cdk-serverless-lamp/workflows/Build/badge.svg)

# Welcome to cdk-serverless-lamp

`cdk-serverless-lamp` is a JSII construct library for AWS CDK that allows you to deploy the [New Serverless LAMP Stack](https://aws.amazon.com/tw/blogs/compute/introducing-the-new-serverless-lamp-stack/) running PHP Laravel Apps by specifying the local `laravel` directory.

By deploying the `ServerlessLaravel` and `DatabaseCluster`, the following resources will be created:

1. Amazon API Gateway HTTP API
2. AWS Lambda custom runtime with [Bref runtime](https://bref.sh/docs/runtimes/) support
3. Amazon Aurora for MySQL database cluster with RDS proxy enabled

## Howto

Create a new Laravel project with AWS CDK

```sh
$ mkdir serverless-lamp && cd serverless-lamp
# create cdk and codebase directories for AWS CDK and Laravel project
$ mkdir cdk codebase
# create the new Laravel project with docker
$ docker run --rm -ti \
  --volume $PWD:/app \
  composer create-project --prefer-dist laravel/laravel ./codebase
# install bref/bref and bref/laravel-bridge in the vendor
$ cd codebase
$ docker run --rm -ti \
  --volume $PWD:/app \
  composer require bref/bref bref/laravel-bridge
# initialize the AWS CDK project
$ cd ../cdk
$ cdk init -l typescript
# install the cdk-severless-lamp npm module
$ yarn add cdk-serverless-lamp
```

Now your directories should look like this:

```
.
├── cdk
└── codebase
```

where `cdk` is for the AWS CDK and `codebase` for Laravel project.

# AWS CDK sample

Building your serverless Laravel with `ServerlessLaravel` construct:

Update `./cdk/lib/cdk-stack.ts`

```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.core as cdk
import path as path
from cdk_serverless_lamp import ServerlessLaravel

class CdkStack(cdk.Stack):
    def __init__(self, scope, id, *, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):
        super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)

        ServerlessLaravel(self, "ServerlessLaravel",
            bref_layer_version="arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12",
            laravel_path=path.join(__dirname, "../../codebase")
        )
```

deploy the CDK stack:

```sh
# see the difference before the deployment
$ cdk diff
# deploy it
$ cdk deploy
```

On deploy complete, the API Gateway URL will be returned in the Output. Click the URL and you will see the Laravel landing page:

![laravel-welcome](./images/laravel.png)

## Amazon Aurora support

Use `DatabaseCluster` to create the your database cluster:

```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.core as cdk
from aws_cdk.aws_ec2 import InstanceType, Vpc
import path as path
from cdk_serverless_lamp import ServerlessLaravel, DatabaseCluster

class CdkStack(cdk.Stack):
    def __init__(self, scope, id, *, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):
        super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)

        vpc = Vpc(self, "Vpc", max_azs=3, nat_gateways=1)

        # the DatabaseCluster sharing the same vpc with the ServerlessLaravel
        db = DatabaseCluster(self, "DatabaseCluster",
            vpc=vpc,
            instance_type=InstanceType("t3.small"),
            rds_proxy=True
        )

        # the ServerlessLaravel
        ServerlessLaravel(self, "ServerlessLaravel",
            bref_layer_version="arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12",
            laravel_path=path.join(__dirname, "../../codebase"),
            vpc=vpc,
            database_config={
                "writer_endpoint": db.rds_proxy.endpoint
            }
        )
```

## Local Development

Create `docker-compose.yml` with the following content:

```docker-compose
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/task
```

and run this command `docker-compose up -d` and now you can access [http://localhost:8000](http://localhost:8000).

*(more information can be found in [bref documentation](https://bref.sh/docs/local-development.html))*



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aws-samples/cdk-serverless-lamp.git",
    "name": "cdk-serverless-lamp",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Pahud Hsieh<hunhsieh@amazon.com>",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/3a/22/5ba2b668ba5cfcb4f06eeb4034c64d50743c5db0712a402fada77c70f85b/cdk-serverless-lamp-1.4.50.tar.gz",
    "platform": "",
    "description": "[![NPM version](https://badge.fury.io/js/cdk-serverless-lamp.svg)](https://badge.fury.io/js/cdk-serverless-lamp)\n[![PyPI version](https://badge.fury.io/py/cdk-serverless-lamp.svg)](https://badge.fury.io/py/cdk-serverless-lamp)\n![Build](https://github.com/aws-samples/cdk-serverless-lamp/workflows/Build/badge.svg)\n\n# Welcome to cdk-serverless-lamp\n\n`cdk-serverless-lamp` is a JSII construct library for AWS CDK that allows you to deploy the [New Serverless LAMP Stack](https://aws.amazon.com/tw/blogs/compute/introducing-the-new-serverless-lamp-stack/) running PHP Laravel Apps by specifying the local `laravel` directory.\n\nBy deploying the `ServerlessLaravel` and `DatabaseCluster`, the following resources will be created:\n\n1. Amazon API Gateway HTTP API\n2. AWS Lambda custom runtime with [Bref runtime](https://bref.sh/docs/runtimes/) support\n3. Amazon Aurora for MySQL database cluster with RDS proxy enabled\n\n## Howto\n\nCreate a new Laravel project with AWS CDK\n\n```sh\n$ mkdir serverless-lamp && cd serverless-lamp\n# create cdk and codebase directories for AWS CDK and Laravel project\n$ mkdir cdk codebase\n# create the new Laravel project with docker\n$ docker run --rm -ti \\\n  --volume $PWD:/app \\\n  composer create-project --prefer-dist laravel/laravel ./codebase\n# install bref/bref and bref/laravel-bridge in the vendor\n$ cd codebase\n$ docker run --rm -ti \\\n  --volume $PWD:/app \\\n  composer require bref/bref bref/laravel-bridge\n# initialize the AWS CDK project\n$ cd ../cdk\n$ cdk init -l typescript\n# install the cdk-severless-lamp npm module\n$ yarn add cdk-serverless-lamp\n```\n\nNow your directories should look like this:\n\n```\n.\n\u251c\u2500\u2500 cdk\n\u2514\u2500\u2500 codebase\n```\n\nwhere `cdk` is for the AWS CDK and `codebase` for Laravel project.\n\n# AWS CDK sample\n\nBuilding your serverless Laravel with `ServerlessLaravel` construct:\n\nUpdate `./cdk/lib/cdk-stack.ts`\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nimport aws_cdk.core as cdk\nimport path as path\nfrom cdk_serverless_lamp import ServerlessLaravel\n\nclass CdkStack(cdk.Stack):\n    def __init__(self, scope, id, *, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):\n        super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)\n\n        ServerlessLaravel(self, \"ServerlessLaravel\",\n            bref_layer_version=\"arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12\",\n            laravel_path=path.join(__dirname, \"../../codebase\")\n        )\n```\n\ndeploy the CDK stack:\n\n```sh\n# see the difference before the deployment\n$ cdk diff\n# deploy it\n$ cdk deploy\n```\n\nOn deploy complete, the API Gateway URL will be returned in the Output. Click the URL and you will see the Laravel landing page:\n\n![laravel-welcome](./images/laravel.png)\n\n## Amazon Aurora support\n\nUse `DatabaseCluster` to create the your database cluster:\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nimport aws_cdk.core as cdk\nfrom aws_cdk.aws_ec2 import InstanceType, Vpc\nimport path as path\nfrom cdk_serverless_lamp import ServerlessLaravel, DatabaseCluster\n\nclass CdkStack(cdk.Stack):\n    def __init__(self, scope, id, *, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):\n        super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)\n\n        vpc = Vpc(self, \"Vpc\", max_azs=3, nat_gateways=1)\n\n        # the DatabaseCluster sharing the same vpc with the ServerlessLaravel\n        db = DatabaseCluster(self, \"DatabaseCluster\",\n            vpc=vpc,\n            instance_type=InstanceType(\"t3.small\"),\n            rds_proxy=True\n        )\n\n        # the ServerlessLaravel\n        ServerlessLaravel(self, \"ServerlessLaravel\",\n            bref_layer_version=\"arn:aws:lambda:us-east-1:209497400698:layer:php-74-fpm:12\",\n            laravel_path=path.join(__dirname, \"../../codebase\"),\n            vpc=vpc,\n            database_config={\n                \"writer_endpoint\": db.rds_proxy.endpoint\n            }\n        )\n```\n\n## Local Development\n\nCreate `docker-compose.yml` with the following content:\n\n```docker-compose\nversion: \"3.5\"\nservices:\n  web:\n    image: bref/fpm-dev-gateway\n    ports:\n      - \"8000:80\"\n    volumes:\n      - ./laravel:/var/task\n    depends_on:\n      - php\n    environment:\n      HANDLER: public/index.php\n  php:\n    image: bref/php-74-fpm-dev\n    volumes:\n      - ./laravel:/var/task\n```\n\nand run this command `docker-compose up -d` and now you can access [http://localhost:8000](http://localhost:8000).\n\n*(more information can be found in [bref documentation](https://bref.sh/docs/local-development.html))*\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A JSII construct lib to build AWS Serverless LAMP with AWS CDK",
    "version": "1.4.50",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "37d90009257b285b08dbdf839f19cae6",
                "sha256": "5e0e3fa2cac956c5a06b82e7cbfa3e0f989455180579df74645efe4934e5995e"
            },
            "downloads": -1,
            "filename": "cdk_serverless_lamp-1.4.50-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "37d90009257b285b08dbdf839f19cae6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 42258,
            "upload_time": "2021-09-27T16:05:02",
            "upload_time_iso_8601": "2021-09-27T16:05:02.260179Z",
            "url": "https://files.pythonhosted.org/packages/68/75/fcb8d479bde202194ef5c9fa12ceb80d46ac65e14e5c68353c2a0b337d71/cdk_serverless_lamp-1.4.50-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "95a3d0901b5751f6ddec33efa5c5a97e",
                "sha256": "508847842d49f3bb3137d4bd5461c64e81d29494067a7508968391e28cdcab68"
            },
            "downloads": -1,
            "filename": "cdk-serverless-lamp-1.4.50.tar.gz",
            "has_sig": false,
            "md5_digest": "95a3d0901b5751f6ddec33efa5c5a97e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 42921,
            "upload_time": "2021-09-27T16:05:03",
            "upload_time_iso_8601": "2021-09-27T16:05:03.732768Z",
            "url": "https://files.pythonhosted.org/packages/3a/22/5ba2b668ba5cfcb4f06eeb4034c64d50743c5db0712a402fada77c70f85b/cdk-serverless-lamp-1.4.50.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-09-27 16:05:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "aws-samples",
    "github_project": "cdk-serverless-lamp.git",
    "lcname": "cdk-serverless-lamp"
}
        
Elapsed time: 0.31905s