in packages/blueprints/sam-serverless-app/src/blueprint.ts [172:274]
override synth(): void {
const runtime = this.options.runtime;
const runtimeOptions = runtimeMappings[runtime];
// create an MDE workspace
this.createMDEWorkspace({ runtimeOptions });
// create an environment
new Environment(this, this.options.environment);
// create SAM template and installation scripts
this.createSamTemplate({
runtime: runtimeOptions.runtime,
codeUri: runtimeOptions.codeUri,
handler: runtimeOptions.handler,
templateProps: runtimeOptions.templateProps,
templateMetadata: runtimeOptions.templateMetadata,
});
// create additional files required for this runtime
const context: FileTemplateContext = {
repositoryRelativePath: this.repository.relativePath,
lambdaFunctionName: this.options.lambda?.functionName ?? '.',
};
for (const fileTemplate of runtimeOptions.filesToCreate) {
new SampleFile(this, fileTemplate.resolvePath(context), { contents: fileTemplate.resolveContent(context) });
}
// create the build and release workflow
const workflowName = 'build-and-release';
this.createWorkflow({
name: 'build-and-release',
outputArtifactName: 'build_result',
stepsToRunUnitTests: runtimeOptions.stepsToRunUnitTests,
autoDiscoveryOverride: runtimeOptions.autoDiscoveryOverride,
runtimeOptions,
});
// create the cleanup workflow
const cleanupWorkflow = new WorkflowBuilder(this, emptyWorkflow);
cleanupWorkflow.setName(DEFAULT_DELETE_RESOURCE_WORKFLOW_NAME);
cleanupWorkflow.addCfnCleanupAction({
actionName: `delete_${this.options.code.cloudFormationStackName}`,
environment: {
Name: this.options.environment.name || '<<PUT_YOUR_ENVIRONMENT_NAME_HERE>>',
Connections: [
{
Name: this.options.environment.awsAccountConnection?.name || ' ',
Role: this.options.environment.awsAccountConnection?.buildRole?.name || ' ',
},
],
},
stackName: this.options.code.cloudFormationStackName,
region: 'us-west-2',
templateBucketName: this.options.cleanupWorkflowTemplateBucketName,
});
const additionalComments = [
'The following workflow is intentionally disabled by the blueprint author to prevent project contributors from accidentally executing it.',
'This workflow will attempt to delete all the deployed resources from the blueprint.',
'The deletion action cannot be undone, please proceed at your own risk.',
'To utilize it, please uncomment all the succeeding lines.',
];
new Workflow(this, this.repository, cleanupWorkflow.definition, {
additionalComments: this.options.uncommentCleanupWorkflow ? undefined : additionalComments,
commented: !this.options.uncommentCleanupWorkflow,
});
// generate the readme
new SourceFile(
this.repository,
'README.md',
generateReadmeContents({
runtime,
runtimeMapping: runtimeOptions,
defaultReleaseBranch: 'main',
lambdas: [this.options.lambda],
environment: this.options.environment,
cloudFormationStackName: this.options.code.cloudFormationStackName,
workflowName: workflowName,
sourceRepositoryName: this.repository.title,
}),
);
const toDeletePath = this.populateLambdaSourceCode({
runtime: runtimeOptions.runtime,
cacheDir: runtimeOptions.cacheDir,
gitSrcPath: runtimeOptions.gitSrcPath,
filesToOverride: runtimeOptions.filesToOverride,
});
super.synth();
cp.execSync(`rm -rf ${toDeletePath}`);
// update permissions
const permissionChangeContext: FileTemplateContext = {
repositoryRelativePath: path.join(this.outdir, this.repository.relativePath),
lambdaFunctionName: this.options.lambda?.functionName ?? '.',
};
for (const filePermissionChange of runtimeOptions.filesToChangePermissionsFor) {
fs.chmodSync(filePermissionChange.resolvePath(permissionChangeContext), getFilePermissions(filePermissionChange.newPermissions));
}
}