Skip to content

Instantly share code, notes, and snippets.

@s0enke
Created August 29, 2022 06:48
Show Gist options
  • Save s0enke/499af16f0e2f049c1d58f6b6c045005f to your computer and use it in GitHub Desktop.
Save s0enke/499af16f0e2f049c1d58f6b6c045005f to your computer and use it in GitHub Desktop.
CDK code for serverless PHP with Lambda and bref.sh
import { CfnOutput, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as apigateway from "@aws-cdk/aws-apigatewayv2-alpha";
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
import * as cdk from "aws-cdk-lib";
export class CdkBrefStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const handler = new lambda.Function(this, "PhpRuntime", {
runtime: lambda.Runtime.PROVIDED_AL2,
handler: "public/index.php",
code: lambda.Code.fromAsset("./backend"),
memorySize: 1024,
layers: [
lambda.LayerVersion.fromLayerVersionArn(
this,
"php-81-fpm",
`arn:aws:lambda:eu-central-1:209497400698:layer:php-81-fpm:28`
),
],
});
const api = new apigateway.HttpApi(this, "HttpApi");
const lambdaHandlerIntegration = new HttpLambdaIntegration(
"Integration",
handler
);
api.addRoutes({
path: "/",
methods: [apigateway.HttpMethod.GET],
integration: lambdaHandlerIntegration,
});
new CfnOutput(this, "Url", {
value: api.url!,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment