/
auth-lambda-stack.ts
61 lines (57 loc) · 1.86 KB
/
auth-lambda-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {
aws_dynamodb as dynamodb,
aws_lambda_nodejs as lambda_nodejs,
aws_lambda as lambda,
Duration,
} from 'aws-cdk-lib';
import * as path from 'path';
import { Construct } from 'constructs';
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { deployEnv } from './envSpecific';
export interface AuthLambdaStackProps {
dbUtilLayer: lambda.LayerVersion;
continuumTable: dynamodb.ITable;
secretManagerPolicy: PolicyStatement;
}
export class AuthLambdaStack extends Construct {
public readonly authGithubLambda: lambda_nodejs.NodejsFunction;
constructor(scope: Construct, id: string, props: AuthLambdaStackProps) {
super(scope, id);
this.authGithubLambda = new lambda_nodejs.NodejsFunction(
this,
'authGithub',
{
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'handler',
entry: path.join(
`${__dirname}/../`,
'functions',
'authGithub/index.ts',
),
environment: {
TableName: props.continuumTable.tableName,
GITHUB_CLIENT_ID:
deployEnv() === 'dev'
? 'b3618911274da67ecaf8'
: 'f77d2946ff61985f83d0',
REDIRECT_URL:
deployEnv() === 'dev'
? 'https://continuum-swart.vercel.app'
: 'https://continuum.tomoima525.com',
continuum_github_key: `continuum_github_key_${deployEnv()}`,
continuum_github_key_local: 'continuum_github_key_local',
},
timeout: Duration.seconds(25),
memorySize: 256,
bundling: {
externalModules: [
'aws-sdk', // Use the 'aws-sdk' available in the Lambda runtime
],
},
layers: [props.dbUtilLayer],
},
);
props.continuumTable.grantReadWriteData(this.authGithubLambda);
this.authGithubLambda.addToRolePolicy(props.secretManagerPolicy);
}
}