forked from boale/rs-cart-api
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy api as AWS Lambda using AWS CDK
- Loading branch information
Showing
10 changed files
with
1,026 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"app": "npx ts-node deploy/App.ts", | ||
"context": { | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:stackRelativeExports": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true, | ||
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, | ||
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
|
||
import { Stack } from './Stack'; | ||
|
||
const app = new cdk.App({}); | ||
|
||
new Stack(app, 'nodejs-aws-cart-api', { | ||
env: { | ||
region: 'eu-central-1', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as lambda from 'aws-cdk-lib/aws-lambda'; | ||
import * as nodejs from 'aws-cdk-lib/aws-lambda-nodejs'; | ||
import { Construct } from 'constructs'; | ||
|
||
export class Stack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const server = new nodejs.NodejsFunction(this, 'server', { | ||
functionName: 'nodejs-aws-cart-api', | ||
entry: 'dist/main.lambda.js', | ||
timeout: cdk.Duration.seconds(30), | ||
memorySize: 1024, | ||
runtime: lambda.Runtime.NODEJS_20_X, | ||
environment: { | ||
RDS_CONNECTION_URL: '<UPDATED_ME>', | ||
}, | ||
bundling: { | ||
externalModules: [ | ||
'@nestjs/microservices', | ||
'@nestjs/websockets', | ||
'class-transformer', | ||
'class-validator', | ||
], | ||
}, | ||
}); | ||
|
||
// exposes the lambda function via HTTP URL | ||
const { url } = server.addFunctionUrl({ | ||
authType: lambda.FunctionUrlAuthType.NONE, | ||
cors: { allowedOrigins: ['*'] }, | ||
}); | ||
|
||
new cdk.CfnOutput(this, 'Url', { value: url }); | ||
} | ||
} |
Oops, something went wrong.