Skip to content

chore(docs): output the Layer ARN to a artifact #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/reusable_deploy_layer_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ jobs:
- name: unzip artefact
run: unzip cdk.out.zip
- name: CDK Deploy Layer
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerStack' --require-approval never --verbose
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerStack' --require-approval never --verbose --outputs-file cdk-outputs.json
- name: Store latest layer ARN
if: ${{ inputs.stage == 'PROD' }}
run: jq -c '.LayerStack.LatestLayerArn' cdk-outputs.json > cdk-layer-stack-${{ matrix.region }}-layer-version.txt
- name: CDK Deploy Canary
run: cdk deploy --app cdk.out --context region=${{ matrix.region}} --parameters DeployStage="${{ inputs.stage }}" 'CanaryStack' --require-approval never --verbose
- name: Save layer stack ARN artifact
uses: actions/upload-artifacts@v3
with:
name: cdk-layer-stack
path: cdk-layer-stack*
30 changes: 30 additions & 0 deletions docs/plugins/lambda_layer_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import re
from pathlib import Path

from mkdocs.config import Config
from mkdocs.structure.files import Files
from mkdocs.structure.pages import Page


def inject(markdown: str, page: Page, config: Config, files: Files):
if not page.is_homepage:
return markdown

# Try to see if we have a cdk-layer-stack directory.
# This is created during the layer build, saved as an artifact, and downloaded before the jobs runs
if not os.path.exists("cdk-layer-stack"):
print("No cdk-layer-stack directory found, not replacing lambda layer versions")
return markdown

# For each cdk output file, replace all the lambda layer occurrences in the docs
files = Path("cdk-layer-stack").glob("*")
for cdk_file in files:
with open(cdk_file, "r") as f:
layer_version_arn = f.readlines()[0].strip()
layer_version_prefix = ":".join(layer_version_arn.split(":")[:-1])

# replace the prefix with the new version
markdown = re.sub(rf"{layer_version_prefix}:\d+", layer_version_arn, markdown)

return markdown
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ copyright: Copyright © 2022 Amazon Web Services
plugins:
- git-revision-date
- search
- mkdocs-simple-hooks:
hooks:
on_page_markdown: "docs.plugins.lambda_layer_version:inject"

extra_css:
- stylesheets/extra.css
Expand Down
Loading