Skip to content

Commit

Permalink
proxy lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
victorekpo committed Jul 12, 2024
1 parent 62e5068 commit 2301af5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 114 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion client/assets/pages.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/src/views/pages/body.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
</div>

<h3>This template is rendered by Handlebars in a Cloudflare Worker</h3>
<h3>This template is rendered by Handlebars in a Cloudflare Worker!</h3>

<p>
<strong>Your name:</strong> {{name}}
Expand Down
50 changes: 0 additions & 50 deletions server/src/api.ts

This file was deleted.

69 changes: 7 additions & 62 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,11 @@ import { Construct } from 'constructs';
import * as Lambda from "aws-cdk-lib/aws-lambda";
import * as Apigw from 'aws-cdk-lib/aws-apigateway';
import { createLambda, createLambdaFunctions } from "./lambda";
import { createApiModels, linkBackendApi } from "./api";

export class ServerlessBackendStack extends CDK.Stack {
constructor(scope: Construct, id: string, props?: CDK.StackProps) {
super(scope, id, props);

/**
* Simple API Gateway proxy integration
*/
const api = new Apigw.RestApi(this, 'ServerlessSagaPattern', {
restApiName: 'Serverless Saga Pattern',
description: 'This service handles serverless saga pattern.',
deployOptions: {
stageName: 'test', // Create the "test" stage initially
},
});
console.log('New API');

// Add the health check route with a mock integration
const healthResource = api.root.addResource('health');
healthResource.addMethod('GET', new Apigw.MockIntegration({
integrationResponses: [{
statusCode: '200',
responseTemplates: {
'application/json': JSON.stringify({ message: 'Health check OK' }),
},
}],
requestTemplates: {
'application/json': '{"statusCode": 200}',
},
}), {
methodResponses: [{
statusCode: '200',
responseModels: {
'application/json': Apigw.Model.EMPTY_MODEL,
},
}],
});

// Layers
const awsSdkLayer = new Lambda.LayerVersion(this, 'AWSdkLayer', {
code: Lambda.Code.fromAsset('src/layers/aws-sdk'),
Expand All @@ -62,39 +28,18 @@ export class ServerlessBackendStack extends CDK.Stack {

const { backendServerlessLambda } = createLambdaFunctions(this, createLambda, layers)

// Create Api Models (request, response)
const { responseModel } = createApiModels(this, api);

// Link Saga to API
linkBackendApi(this, api, backendServerlessLambda, responseModel);

// Deploy the API Gateway stage
const deployment = new Apigw.Deployment(this, 'Deployment', {
api,
});

console.log("Redeploying API with new methods");
new Apigw.Stage(this, 'ProdStage', {
deployment,
stageName: 'prod',
/**
* Simple API Gateway proxy integration
*/
const api = new Apigw.LambdaRestApi(this, 'ServerlessSagaPattern', {
handler: backendServerlessLambda
});
console.log('New API');

// Export the API Gateway URL
new CDK.CfnOutput(this, 'ApiGatewayUrlOutput', {
value: api.url,
exportName: 'ApiGatewayUrlOutput'
});

// Export the API Gateway RestApiId
new CDK.CfnOutput(this, 'ApiGatewayRestApiIdOutput', {
value: api.restApiId,
exportName: 'ApiGatewayRestApiIdOutput'
});

// Export the API Gateway RootResourceId
new CDK.CfnOutput(this, 'ApiGatewayRootResourceIdOutput', {
value: api.root.resourceId,
exportName: 'ApiGatewayRootResourceIdOutput'
exportName: 'BackendApiGatewayUrlOutput'
});
}
}
Expand Down

0 comments on commit 2301af5

Please sign in to comment.