diff --git a/.github/workflows/aws-cdk-synth.yml b/.github/workflows/aws-cdk-synth.yml index ce3598b..ba18521 100644 --- a/.github/workflows/aws-cdk-synth.yml +++ b/.github/workflows/aws-cdk-synth.yml @@ -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 + # }) diff --git a/echo b/echo deleted file mode 100644 index 6145bd0..0000000 --- a/echo +++ /dev/null @@ -1 +0,0 @@ -{"version":"9.0.0"} \ No newline at end of file diff --git a/event_bridge_aws_cdk/event_bridge_aws_cdk_stack.py b/event_bridge_aws_cdk/event_bridge_aws_cdk_stack.py index 5b87f7d..2336eee 100644 --- a/event_bridge_aws_cdk/event_bridge_aws_cdk_stack.py +++ b/event_bridge_aws_cdk/event_bridge_aws_cdk_stack.py @@ -11,18 +11,26 @@ 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( @@ -30,10 +38,17 @@ def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None: 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)) diff --git a/requirements.txt b/requirements.txt index 37e609c..f149158 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file