Skip to content
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

testing dlq and dlq as source to lambda #17

Merged
merged 8 commits into from
Apr 4, 2021
Merged
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
59 changes: 45 additions & 14 deletions .github/workflows/aws-cdk-synth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,51 @@ jobs:

- name: "Run cdk synth"
id: synth
run: cdk synth --json EventBridgeAwsCdkStack | grep Type 2>&1 | tee cdk.log

- name: Add synth comment to PR
env:
URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
run: |
cdk synth --output=./templates
echo "##[set-output name=stdoutplan;]$(cat ./templates/EventBridgeAwsCdkStack.template.json)"
jq --raw-input --slurp '{body: .}' cdk.log > cdk.json
curl \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
-d @cdk.json \
-X POST \
$URL

- name: Run CDK diff
run: cdk diff -c aws-cdk:enableDiffNoFail=true --no-color --app cdk.out "*" 2>&1 | tee cdk1.log

- name: "Run - CDK synth Comment"
uses: actions/github-script@0.9.0
- name: Add diff comment to PR
env:
STDOUT: "```${{ steps.synth.outputs.stdoutplan }}```"
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.STDOUT
})
URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
run: |
jq --raw-input --slurp '{body: .}' cdk1.log > cdk1.json
curl \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
-d @cdk1.json \
-X POST \
$URL

# run: |
# cdk synth --output=./templates
# echo "##[set-output name=stdoutplan;]$(<./templates/EventBridgeAwsCdkStack.template.json)"
#
# - name: "Run - CDK synth Comment"
# uses: actions/github-script@0.9.0
# env:
# STDOUT: "```${{ steps.synth.outputs.stdoutplan }}```"
# with:
# github-token: ${{ secrets.GIT_PAT }}
# script: |
# github.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: process.env.STDOUT
# })
1 change: 0 additions & 1 deletion echo

This file was deleted.

19 changes: 17 additions & 2 deletions event_bridge_aws_cdk/event_bridge_aws_cdk_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,44 @@
import aws_cdk.aws_events as events
import aws_cdk.aws_sqs as sqs
import aws_cdk.aws_events_targets as targets
import aws_cdk.aws_logs as logs
from aws_cdk.aws_lambda_event_sources import SqsEventSource

class EventBridgeAwsCdkStack(cdk.Stack):

def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

queue = sqs.Queue(self, "Queue")

fn = lambda_.Function(self, "ETL_job_func",
runtime=lambda_.Runtime.PYTHON_3_8,
handler="lambda_function.handler",
code=lambda_.Code.asset('lambda')
code=lambda_.Code.asset('lambda'),
dead_letter_queue=queue
)


fn.add_event_source(SqsEventSource(queue))

rule = events.Rule(
self, "Rule",
schedule=events.Schedule.cron(
minute='0',
hour='11')
)

queue = sqs.Queue(self, "Queue")

rule.add_target(targets.LambdaFunction(fn,
dead_letter_queue=queue, # Optional: add a dead letter queue
max_event_age=cdk.Duration.hours(2), # Otional: set the maxEventAge retry policy
retry_attempts=2
))


log_group = logs.LogGroup(self, "EventsLogGroup",
log_group_name="EventsLogGroup"
)


rule.add_target(targets.CloudWatchLogGroup(log_group))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ aws_cdk.aws_lambda
aws_cdk.aws_events
aws_cdk.aws_sqs
aws_cdk.aws_events_targets
aws_cdk.aws_logs
aws_cdk.aws_lambda_event_sources