Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
feat: adding lambda layer documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arantespp committed Oct 24, 2020
1 parent 278048a commit c8dafe7
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 19 deletions.
4 changes: 3 additions & 1 deletion packages/cli/src/deploy/cloudFormation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const logPrefix = 'cloudformation';
log.addLevel('event', 10000, { fg: 'yellow' });
log.addLevel('output', 10000, { fg: 'blue' });

// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html
/**
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html
*/
const TEMPLATE_BODY_MAX_SIZE = 51200;

const isTemplateBodyGreaterThanMaxSize = (
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/deploy/lambdaLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const getZipNodeModules = async () => {
return zip.toBuffer();
};

/**
* The CloudFormation template created to deploy a Lambda Layer.
*
* - The Description fields of the Output and the LambdaLayer resource use the
* name and version of the package.json dependencies and is limited to a limit
* defined by: {@link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-description}
* - The Layer name is the same as the Stack name.
*/
export const getLambdaLayerTemplate = (): CloudFormationTemplate => {
const { dependencies } = (() => {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/website/api/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const commands = [
'deploy',
'deploy base-stack',
'deploy static-app',
'deploy lambda-layer',
];
9 changes: 0 additions & 9 deletions packages/website/api/getComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,3 @@ export const getComments = <O extends Record<string, string>>(
};
}, {} as any);
};

export const tt = () =>
jsdoc.explainSync({
files: path.resolve(
process.cwd(),
'../cli/dist',
'deploy/staticApp/staticApp.template.js',
),
});
2 changes: 0 additions & 2 deletions packages/website/api/getTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { dumpToYamlCloudFormationTemplate } from 'carlin/dist/utils';
import { CloudFormationTemplate } from 'carlin/dist/utils/cloudFormationTemplate';

export { getStaticAppTemplate } from 'carlin/dist/deploy/staticApp/staticApp.template';

export type JsonYamlTemplates = {
templateJson: any;
templateYaml: string;
Expand Down
5 changes: 4 additions & 1 deletion packages/website/api/vars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { getLambdaLayerTemplate } from 'carlin/dist/deploy/lambdaLayer';

export {
originCacheExpression,
getLambdaEdgeOriginResponseZipFile,
getStaticAppTemplate,
originCacheExpression,
} from 'carlin/dist/deploy/staticApp/staticApp.template';
4 changes: 4 additions & 0 deletions packages/website/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const navs: Array<{
name: 'deploy static-app',
href: '/docs/usage/deploy-static-app',
},
{
name: 'deploy lambda-layer',
href: '/docs/usage/deploy-lambda-layer',
},
],
},
{
Expand Down
98 changes: 98 additions & 0 deletions packages/website/pages/docs/usage/deploy-lambda-layer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Styled } from 'theme-ui';

import { getComments } from '../../../api/getComments';
import { getJsonYamlTemplates } from '../../../api/getTemplates';
import { getLambdaLayerTemplate } from '../../../api/vars';

import CodeBlock from '../../../components/CodeBlock';

export const getStaticProps = async () => {
const root = {
comments: getComments({
deployLambdaLayer: 'deploy/lambdaLayer.js',
getLambdaLayerTemplate: 'deploy/lambdaLayer.js',
}),
};

const lambdaLayerTemplateYaml = getJsonYamlTemplates(getLambdaLayerTemplate())
.templateYaml;

return { props: { root, lambdaLayerTemplateYaml } };
};

type ThenArg<T> = T extends PromiseLike<infer U> ? U : T;

type Props = ThenArg<ReturnType<typeof getStaticProps>>['props'];

const DocsUsageDeployStaticApp = ({ root, lambdaLayerTemplateYaml }: Props) => {
return (
<article>
<Styled.h1>deploy lambda-layer</Styled.h1>
<section>
<CodeBlock>carlin deploy lambda-layer</CodeBlock>
<Styled.p>
<span>When you execute </span>
<Styled.code>deploy lambda-layer</Styled.code>
<span>, these steps are performed:</span>
</Styled.p>
<CodeBlock>{root.comments.deployLambdaLayer}</CodeBlock>
</section>
<section>
<Styled.p>
<span>The CloudFormation template created (in this example, </span>
<Styled.code>Description </Styled.code>
<span>
fields were created using the dependencies of this website):
</span>
</Styled.p>
<CodeBlock className="sh">
{root.comments.getLambdaLayerTemplate}
</CodeBlock>
<CodeBlock className="yaml">{lambdaLayerTemplateYaml}</CodeBlock>
</section>
{/* <Styled.h2>Usage</Styled.h2>
<section>
<Styled.h3>Only S3 Bucket</Styled.h3>
<Styled.p>
This deploy creates a single bucket to host de static files. The
template created is shown below:
</Styled.p>
<CodeBlock className="yaml">{onlyS3.template.templateYaml}</CodeBlock>
</section>
<section>
<Styled.h3>CloudFront</Styled.h3>
<Styled.p>
Besides creating a S3 bucket, this deploy also add CloudFront to
deployment. Lambda@Edge is used together with CloudFront whose
functionality is explained below:
</Styled.p>
<CodeBlock className="js">
{[
cloudfront.comments.getLambdaEdgeOriginResponseZipFile,
'\n',
cloudfront.comments.originCacheExpression,
`const originCacheExpression = '${cloudfront.originCacheExpression}';`,
].join('\n')}
</CodeBlock>
<Styled.p>The Lambda@Edge code is show below:</Styled.p>
<CodeBlock className="js">
{cloudfront.getLambdaEdgeOriginResponseZipFile}
</CodeBlock>
<Styled.p>
<span>The Lambda@Edge code with custom SCP </span>
<Styled.code>{cloudfront.customScp}</Styled.code>
<span> is show below:</span>
</Styled.p>
<CodeBlock className="js">
{cloudfront.getLambdaEdgeOriginResponseZipFileWithScp}
</CodeBlock>
<Styled.p>The CloudFormation template created is shown below:</Styled.p>
<CodeBlock className="yaml">
{cloudfront.template.templateYaml}
</CodeBlock> */}
{/* </section> */}
</article>
);
};

export default DocsUsageDeployStaticApp;
13 changes: 7 additions & 6 deletions packages/website/pages/docs/usage/deploy-static-app.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Styled } from 'theme-ui';

import { getComments } from '../../../api/getComments';
import {
getJsonYamlTemplates,
getStaticAppTemplate,
} from '../../../api/getTemplates';
import { getJsonYamlTemplates } from '../../../api/getTemplates';
import * as apiVars from '../../../api/vars';

import CodeBlock from '../../../components/CodeBlock';
Expand All @@ -18,13 +15,17 @@ export const getStaticProps = async () => {

const onlyS3 = (() => {
const options = { cloudfront: false, spa: false };
const template = getJsonYamlTemplates(getStaticAppTemplate(options));
const template = getJsonYamlTemplates(
apiVars.getStaticAppTemplate(options),
);
return { options, template };
})();

const cloudfront = (() => {
const options = { cloudfront: true, spa: false };
const template = getJsonYamlTemplates(getStaticAppTemplate(options));
const template = getJsonYamlTemplates(
apiVars.getStaticAppTemplate(options),
);
const comments = getComments({
getLambdaEdgeOriginResponseZipFile:
'deploy/staticApp/staticApp.template.js',
Expand Down

0 comments on commit c8dafe7

Please sign in to comment.