Skip to content

Commit

Permalink
Merge pull request #17 from thakurrishabh/dev
Browse files Browse the repository at this point in the history
 testing dlq and dlq as source to lambda
  • Loading branch information
thakurrishabh authored Apr 4, 2021
2 parents a354374 + cf1cb4e commit ead822d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
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/[email protected]
- 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/[email protected]
# 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

0 comments on commit ead822d

Please sign in to comment.