Frank
📢 UpdateFor those of y’all that’ve been fed up w/ cryptic function names, in v0.54.4, you can now pass in a callback for
functionName
. It allows you to apply a naming convention to some/all of your functions. For example, to name functions based on their handler file names:
import path from "path";
app.setDefaultFunctionProps({
functionName: ({ functionProps, stack }) => (
`${stack.stackName}-${path.parse(functionProps.handler).name}`
)
});
Ross Coundon
12/20/2021, 11:01 PMFrank
Ross Coundon
12/20/2021, 11:03 PMFrank
Adrián Mouly
12/20/2021, 11:12 PMAdrián Mouly
12/20/2021, 11:12 PMAdrián Mouly
12/20/2021, 11:12 PMFrank
app.setDefaultFunctionProps
Adrián Mouly
12/20/2021, 11:13 PMAdrián Mouly
12/20/2021, 11:13 PMAdrián Mouly
12/20/2021, 11:14 PMFrank
functionName
callback. If there isn’t much of a downside, we can add it to all other Constructs.Adrián Mouly
12/20/2021, 11:14 PMAdrián Mouly
12/20/2021, 11:14 PMstack.stackName
would include “-stack”, if we follow existing convention.Adrián Mouly
12/20/2021, 11:15 PMnetworkVpn-stack
.Adrián Mouly
12/20/2021, 11:15 PM-stack
part 😂 .Frank
stack.stackName.split("-").slice(0, -1)
Adrián Mouly
12/20/2021, 11:16 PMAdrián Mouly
12/20/2021, 11:16 PMexport function getNamePrefix(stack: Stack, scope: App): string {
const projectName = stack.stackName.split('-')[2];
return `${scope.stage}-${scope.name}-${projectName}`;
}
Adrián Mouly
12/20/2021, 11:16 PMFrank
stack.stage
gives u the stageAdrián Mouly
12/20/2021, 11:17 PMAdrián Mouly
12/20/2021, 11:17 PMFrank
stackName
should have stage in thereAdrián Mouly
12/20/2021, 11:18 PMFrank
Adrián Mouly
12/20/2021, 11:18 PMMatt Morgan
12/20/2021, 11:19 PMAdrián Mouly
12/20/2021, 11:19 PMconst namePrefix = getNamePrefix(this, scope);
EB rule
ruleName: `${namePrefix}-intercomContact-eventBridgeRule`,
Queue:
queueName: `${namePrefix}-createOrUpdateCompanyDlq`,
Adrián Mouly
12/20/2021, 11:20 PMMatt Morgan
12/20/2021, 11:20 PMAdrián Mouly
12/20/2021, 11:20 PMAdrián Mouly
12/20/2021, 11:21 PMqueue
in the name? should we put function
? or we should just name them based on the business.Adrián Mouly
12/20/2021, 11:22 PMdev-sst-myCoolQueue
-> I tend to do this
dev-sst-messagesToProccess
-> others do this
This is an example, some developers forget to name it.Frank
you can also manage the creation (and thus deletion) of log groups in a stackCurrently, SST/CDK does not explicitly create log groups. AWS Lambda creates them when a function gets invoked for the first time. Are you looking to manually creating them?
Matt Morgan
12/20/2021, 11:24 PMFrank
if (app.stage !== "prod") {
app.setDefaultRemovalPolicy(RemovalPolicy.DESTROY);
}
Matt Morgan
12/20/2021, 11:26 PMFrank
Frank
Matt Morgan
12/20/2021, 11:27 PMFrank
Frank
Matt Morgan
12/20/2021, 11:32 PMFrank
Frank
Matt Morgan
12/20/2021, 11:38 PM--remove-log-groups
. Anyway, don't build it just for me but maybe somebody else cares about this too.Frank
Mehmet Ali SARAÇ
12/28/2021, 10:24 AMMehmet Ali SARAÇ
12/28/2021, 10:24 AMFrank