Created
October 16, 2023 21:57
-
-
Save wz2b/affbf097ee609e36c5ade0a2bb30c134 to your computer and use it in GitHub Desktop.
How I am creating my function
This file contains hidden or 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
const fnSyncHistory = new nodejs.NodejsFunction(this, | |
"craft-sync-history-function", { | |
...lambdaBase.baseLayers, | |
runtime: lambda.Runtime.NODEJS_LATEST, | |
logRetention: RetentionDays.ONE_MONTH, | |
bundling: { | |
sourceMapMode: nodejs.SourceMapMode.INLINE, | |
minify: true | |
}, | |
role: sitewiseRole, | |
architecture: lambda.Architecture.ARM_64, | |
memorySize: 128, | |
timeout: cdk.Duration.seconds(30), | |
reservedConcurrentExecutions: undefined, | |
functionName: "MonnitSyncHistoryFunction", | |
entry: path.join(__dirname, "../lambdas/sync_history.ts"), | |
handler: "handler", | |
environment: { | |
...lambdaBase.environment | |
} | |
}); | |
/* The lambda base referenced above does a bunch of things common to all my lambdas */ | |
export class BaseLambdaConfig { | |
/* ... abbreviated ... */ | |
constructor(private readonly stack: cdk.Stack, environment: { [key: string]: string }) { | |
this.basicLambdaExecutionPolicyStatements = [ | |
new iam.PolicyStatement({ | |
effect: Effect.ALLOW, | |
actions: ["logs:CreateLogGroup"], | |
resources: [`arn:aws:logs:${stack.region}:${stack.account}:*`] | |
}), | |
new iam.PolicyStatement({ | |
effect: Effect.ALLOW, | |
actions: [ | |
"logs:CreateLogStream", | |
"logs:PutLogEvents" | |
], | |
resources: [`arn:aws:logs:${stack.region}:${stack.account}:log-group:/aws/lambda/*:*`] | |
}), | |
new iam.PolicyStatement({ | |
effect: Effect.ALLOW, | |
actions: [ | |
"xray:PutTraceSegments", | |
"xray:PutTelemetryRecords", | |
"xray:GetSamplingRules", | |
"xray:GetSamplingTargets", | |
"xray:GetSamplingStatisticSummaries" | |
], | |
resources: ["*"] | |
}) | |
]; | |
this.basicExecutionPolicy = new iam.Policy(stack, "craft-sync-lambda-policy", { | |
statements: this.basicLambdaExecutionPolicyStatements | |
}); | |
this.baseLayers = { | |
environment: environment, | |
layers: [ | |
lambda.LayerVersion.fromLayerVersionArn( | |
stack, | |
"craft-sync-layer", | |
`arn:aws:lambda:${stack.region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:21` | |
) | |
], | |
bundling: { | |
externalModules: [ | |
'@aws-lambda-powertools/commons', | |
'@aws-lambda-powertools/logger', | |
'@aws-lambda-powertools/metrics', | |
'@aws-lambda-powertools/tracer', | |
'@aws-lambda-powertools/idempotency', | |
'@aws-lambda-powertools/parameters', | |
'@aws-lambda-powertools/batch' | |
], | |
sourceMapMode: SourceMapMode.INLINE, | |
minify: true | |
}, | |
} | |
this.basicExecutionRole = new iam.Role(stack, | |
"craft-sync-basic-lambda-role", { | |
roleName: "craft-sync-basic-lambda-role", | |
assumedBy: this.lambdaServicePrincipal, | |
inlinePolicies: { | |
"basic": this.basicExecutionPolicy.document, | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment