From 838f3c578fb7ec4c5c805a0c929ecc28600beb8b Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 10 Jun 2022 05:12:46 +0200 Subject: [PATCH 1/7] chore(governance): warn message on closed issues --- .github/workflows/on_closed_issues.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/on_closed_issues.yml diff --git a/.github/workflows/on_closed_issues.yml b/.github/workflows/on_closed_issues.yml new file mode 100644 index 00000000000..4c3f9bc1780 --- /dev/null +++ b/.github/workflows/on_closed_issues.yml @@ -0,0 +1,12 @@ +name: Closed Issue Message +on: + issues: + types: [closed] +jobs: + auto_comment: + runs-on: ubuntu-latest + steps: + - uses: aws-actions/closed-issue-message@v1 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + message: "Comments on closed issues are hard for our team to see." From 02af1746ccca88c290188579131afd11d3721dfe Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 10:44:56 +0200 Subject: [PATCH 2/7] docs(tracer): split initial example --- docs/core/tracer.md | 25 +++---------------- examples/tracer/src/capture_lambda_handler.py | 15 +++++++++++ examples/tracer/template.yaml | 23 +++++++++++++++++ 3 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 examples/tracer/src/capture_lambda_handler.py create mode 100644 examples/tracer/template.yaml diff --git a/docs/core/tracer.md b/docs/core/tracer.md index a773ecb52a8..963552c3e99 100644 --- a/docs/core/tracer.md +++ b/docs/core/tracer.md @@ -20,33 +20,16 @@ Tracer is an opinionated thin wrapper for [AWS X-Ray Python SDK](https://github. Before your use this utility, your AWS Lambda function [must have permissions](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html#services-xray-permissions) to send traces to AWS X-Ray. -```yaml hl_lines="6 9" title="AWS Serverless Application Model (SAM) example" -Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function - Properties: - Runtime: python3.8 - Tracing: Active - Environment: - Variables: - POWERTOOLS_SERVICE_NAME: example +```yaml hl_lines="9 12" title="AWS Serverless Application Model (SAM) example" +--8<-- "examples/tracer/template.yaml" ``` ### Lambda handler You can quickly start by initializing `Tracer` and use `capture_lambda_handler` decorator for your Lambda handler. -```python hl_lines="1 3 6" title="Tracing Lambda handler with capture_lambda_handler" -from aws_lambda_powertools import Tracer - -tracer = Tracer() # Sets service via env var -# OR tracer = Tracer(service="example") - -@tracer.capture_lambda_handler -def handler(event, context): - charge_id = event.get('charge_id') - payment = collect_payment(charge_id) - ... +```python hl_lines="1 4 12" title="Tracing Lambda handler with capture_lambda_handler" +--8<-- "examples/tracer/src/capture_lambda_handler.py" ``` `capture_lambda_handler` performs these additional tasks to ease operations: diff --git a/examples/tracer/src/capture_lambda_handler.py b/examples/tracer/src/capture_lambda_handler.py new file mode 100644 index 00000000000..461a31cd213 --- /dev/null +++ b/examples/tracer/src/capture_lambda_handler.py @@ -0,0 +1,15 @@ +from aws_lambda_powertools import Tracer +from aws_lambda_powertools.utilities.typing import LambdaContext + +tracer = Tracer() # Sets service via POWERTOOLS_SERVICE_NAME env var +# OR tracer = Tracer(service="example") + + +def collect_payment(charge_id: str) -> str: + return f"dummy payment collected for charge: {charge_id}" + + +@tracer.capture_lambda_handler +def handler(event: dict, context: LambdaContext) -> str: + charge_id = event.get("charge_id") + return collect_payment(charge_id) diff --git a/examples/tracer/template.yaml b/examples/tracer/template.yaml new file mode 100644 index 00000000000..504661d634d --- /dev/null +++ b/examples/tracer/template.yaml @@ -0,0 +1,23 @@ +AWSTemplateFormatVersion: "2010-09-09" +Transform: AWS::Serverless-2016-10-31 +Description: AWS Lambda Powertools Tracer doc examples + +Globals: + Function: + Timeout: 5 + Runtime: python3.9 + Tracing: Active + Environment: + Variables: + POWERTOOLS_SERVICE_NAME: example + Layers: + # Find the latest Layer version in the official documentation + # https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer + - !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython:21 + +Resources: + CaptureLambdaHandlerExample: + Type: AWS::Serverless::Function + Properties: + CodeUri: src + Handler: capture_lambda_handler.handler From cb4470837035c529daeba99a8025d067a1595413 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 10:46:06 +0200 Subject: [PATCH 3/7] chore(ci): rebuild doc to include examples' changes --- .github/workflows/python_docs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python_docs.yml b/.github/workflows/python_docs.yml index d168e1ae68a..7b842f038d6 100644 --- a/.github/workflows/python_docs.yml +++ b/.github/workflows/python_docs.yml @@ -8,6 +8,7 @@ on: - "docs/**" - "CHANGELOG.md" - "mkdocs.yml" + - "examples/**" jobs: docs: From 466c2bd6428ecea77458512b8e2c9b261aefcbcc Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 10:57:25 +0200 Subject: [PATCH 4/7] chore: add cfn-lint in pre-commit --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97bdef15726..3107b1fe136 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,3 +36,8 @@ repos: hooks: - id: markdownlint args: ["--fix"] + - repo: https://github.com/aws-cloudformation/cfn-python-lint + rev: v0.61.1 + hooks: + - id: cfn-python-lint + files: examples/.*\.(yaml|yml)$ From ef1d90f99c4b83c139bccda056d2e59b4a5efcec Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 11:01:25 +0200 Subject: [PATCH 5/7] feat(ci): include examples folder in linting/fmt --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5ad35546f95..6173e3e310d 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,11 @@ dev: pre-commit install format: - poetry run isort aws_lambda_powertools tests - poetry run black aws_lambda_powertools tests + poetry run isort aws_lambda_powertools tests examples + poetry run black aws_lambda_powertools tests examples lint: format - poetry run flake8 aws_lambda_powertools/* tests/* + poetry run flake8 aws_lambda_powertools tests examples lint-docs: docker run -v ${PWD}:/markdown 06kellyjac/markdownlint-cli "docs" From 87bccfeb2cdb13886e4f4c63ae3291ed9c1f0a7f Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 11:19:42 +0200 Subject: [PATCH 6/7] fix(pre-commit): ensure flake8 includes examples --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3107b1fe136..8a614f78968 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,6 @@ repos: entry: poetry run flake8 language: system types: [python] - exclude: example - repo: https://github.com/igorshubovych/markdownlint-cli rev: "11c08644ce6df850480d98f628596446a526cbc6" # frozen: v0.31.1 hooks: From 7f6ef84c56097d0c901b54589998ce1d551c2825 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Thu, 23 Jun 2022 13:12:20 +0200 Subject: [PATCH 7/7] feat(ci): include cfn-lint in docs workflow --- .github/workflows/python_docs.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python_docs.yml b/.github/workflows/python_docs.yml index 7b842f038d6..3a6e15e5431 100644 --- a/.github/workflows/python_docs.yml +++ b/.github/workflows/python_docs.yml @@ -21,10 +21,15 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3.8" + # Maintenance: temporarily until we drop Python 3.6 and make cfn-lint a dev dependency + - name: Setup Cloud Formation Linter with Latest Version + uses: scottbrenner/cfn-lint-action@v2 - name: Install dependencies run: make dev - name: Lint documentation - run: make lint-docs + run: | + make lint-docs + cfn-lint examples/**/*.yaml - name: Setup doc deploy run: | git config --global user.name Docs deploy