Created
April 10, 2022 22:25
-
-
Save louislatreille/7f27e7e1a836eebe2e5e9a0d3eb51393 to your computer and use it in GitHub Desktop.
Serverless Streamlined - createFunctionHandler.ts
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
import { AwsCfInstruction } from "@serverless/typescript"; | |
import { AuthorizerConfig } from "./utilities"; | |
export type AdditionalPolicyStatement = { | |
Action: string[]; | |
Resource: AwsCfInstruction[]; | |
Effect: "Allow" | "Deny"; | |
}; | |
export const createFunctionHandler = ( | |
functionName: string, | |
path: string, | |
method: string, | |
authorizer?: AuthorizerConfig, | |
policyStatements: AdditionalPolicyStatement[] = [], | |
environmentVariables: { [key: string]: AwsCfInstruction } | undefined = undefined, | |
timeout = 5, | |
memorySize = 256, | |
) => { | |
const resourceName = functionName.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`); | |
return { | |
handler: `./src/functions/${functionName}/handler.main`, | |
environment: environmentVariables, | |
iamRoleStatementsName: `${resourceName}-exec-role-pulumi-serverless-journey`, | |
iamRoleStatementsInherit: true, | |
iamRoleStatements: policyStatements, | |
timeout, | |
memorySize, | |
events: [ | |
{ | |
http: { | |
path, | |
method, | |
authorizer, | |
cors: true, | |
}, | |
}, | |
], | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment