Skip to content

Instantly share code, notes, and snippets.

@louislatreille
Created April 10, 2022 22:25
Show Gist options
  • Save louislatreille/7f27e7e1a836eebe2e5e9a0d3eb51393 to your computer and use it in GitHub Desktop.
Save louislatreille/7f27e7e1a836eebe2e5e9a0d3eb51393 to your computer and use it in GitHub Desktop.
Serverless Streamlined - createFunctionHandler.ts
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