-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Issue#820 - add new CDK example demonstrating AWS CodePipeline based CICD setup #1054
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
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
b73f958
initial commit
ac4aba1
remove cd command
baa5490
added github project path
f4ec8f0
rename stacks
c5e078c
rename stage app stacks
191e7cb
added vpc stack and cross stack reference the vpc in ecs stack
1160de2
added cdk.context.json to .gitignore
jfan9 ef4b1d3
added synthCodeBuildDefaults to fix build stage permission issue
jfan9 e81e690
added architecture diagram
a381c71
added architecture diagram to README>md
528a480
add lambdaApiStack
365bfaf
Merge pull request #3 from kyoonkwon/issue#820
jfan9 8954f34
added import PolicyStatement from cdk lib
jfan9 044a279
Dockerfile and App code
dca5a5e
lesser requirement
c59bb62
added datastore stack
sonal-aws 2f5739f
Update pipeline-stack.ts
sonal-aws e11b6bc
Update pipeline-stack.ts
sonal-aws ca14668
Merge pull request #4 from ruchirshetye-aws/issue#820
fanq10 5d7eb17
Merge pull request #5 from sonal-aws/issue#820
fanq10 30c750c
updated import resource format
ab43c72
added waves to eu-west-1 & us-west-2
1de7188
fix container missing waitress module error
f3a9ea2
Update README.md
ruchirshetye-aws cf2746f
Added sample stack for event sources mapped asynchronous lambda funct…
naxxster b3bf459
Merge pull request #7 from junsjang/issue/820
jfan9 eeea417
Merge pull request #6 from ruchirshetye-aws/patch-1
jfan9 86607f7
added @types/aws-lambda: ^8.10.140
jfan9 92d14c1
updated a new version of diagram
19a4369
Update README.md
jfan9 564af79
relocate async lambda function code to assets
021930f
Merge branch 'main' into issue#820
fanq10 7e5f053
Merge branch 'main' into issue#820
kaiz-io 9124436
Merge branch 'main' into issue#820
jfan9 aa0a2fa
explicit add account id in the pipeline
jfan9 a953af9
Merge branch 'main' into issue#820
jfan9 7cf8ea7
moved variables to app.ts
8421b47
upgrade cdk app version to v2.162.1
f9e0c1e
Merge branch 'main' into issue#820
fanq10 ad87f4f
Merge branch 'main' into issue#820
kaiz-io 972e3cb
Update README.md
kaiz-io 3f29f8c
Delete typescript/aws-codepipeline-ecs-lambda/test/aws-codepipeline-e…
kaiz-io 194c0e5
Update package.json
kaiz-io bc619a2
Delete typescript/aws-codepipeline-ecs-lambda/jest.config.js
kaiz-io 0cb89cd
Update Dockerfile
kaiz-io 62ff408
fix: add DNA for cross account and lookup
352b351
Merge branch 'main' into issue#820
kaiz-io 5b6acfe
Merge branch 'main' into issue#820
jfan9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| *.js | ||
| !jest.config.js | ||
| *.d.ts | ||
| node_modules | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out | ||
| cdk.context.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| *.ts | ||
| !*.d.ts | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # AWS Codepipeline CI/CD Solution for ECS Fargate and Lambda | ||
|
|
||
| ## Architect Design: | ||
|  | ||
|
|
||
| ## Overview | ||
|
|
||
| This CDK package provides a production-grade template for setting up AWS resources to enable smooth migration from monolithic EC2-based architectures to cloud-native solutions on AWS. It's designed for startups looking to scale their infrastructure efficiently. | ||
|
|
||
| Key features: | ||
| - CICD pipeline using AWS CodePipeline | ||
| - Lambda functions (async triggered and REST endpoints behind API Gateway) | ||
| - ECS Fargate based service with automatic deployment | ||
| - Integration with private GitHub repositories | ||
| - Reference to CDK created VPCs | ||
| - Creates RDS Instances with credentials managed by AWS Secrets Manager | ||
| - Event-driven architecture using SQS, SNS, and EventBridge | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Create a Private Github Repository with source code inside 'aws-codepipeline-ecs-lambda' directory. | ||
| - Create a connection to GitHub or GitHub Enterprise Cloud, see [Create a connection to GitHub](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create-github.html). | ||
| - Modify the `connectionArn` in `pipeline-stack.ts` file. | ||
| - Modify `githubOrg`, `githubRepo`, `githubBranch` with your private repository details. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| The project is organized into six main stacks: | ||
|
|
||
| 1. `VpcStack`: Network infrastructure resources | ||
| 2. `DataStoresStack`: Database resources | ||
| 3. `PubSubStack`: Event-based infrastructure (SQS, SNS, EventBridge) | ||
| 4. `AsyncLambdasStack`: Asynchronously triggered Lambda functions | ||
| 5. `LambdaApisStack`: Lambda functions as REST endpoints behind API Gateway | ||
| 6. `EcsFargateStack`: ECS Fargate Service, Cluster, Tasks, and Containers | ||
|
|
||
| You can easily customize the infrastructure by modifying or removing specific stacks in the `lib/pipeline-stage.ts` file. | ||
|
|
||
| ## Solution overview | ||
|
|
||
| The CDK application is structured as follows: | ||
|
|
||
| `lib/pipeline-stack.ts` contains the definition of the CI/CD pipeline. The main component here is the CodePipeline construct that creates the pipeline for us | ||
|
|
||
| `lib/stage-app.ts` contains definitions of all the six stacks which the pipeline will deploy. | ||
|
|
||
| `lib/stage-app-vpc-stack.ts` creates new vpc resource along with subnets, nat gateways and remaining networking infrastructure. | ||
|
|
||
| `lib/stage-app-datastore-stack.ts` creates a Aurora Serverless V2 Cluster along with KMS key to encrypt the database. | ||
|
|
||
| `lib/stage-app-ecs-fargate-stack.ts` builds the `Dockerfile` and creates ecs fargate service along with loadbalancer. | ||
|
|
||
| `lib/stage-app-lambda-api-stack.ts` creates lambda functions as REST endpoints behind API Gateway resource. | ||
|
|
||
| `lib/PubSubStack.ts` creates sns, eventbridge and lambda function. | ||
|
|
||
| --- |
7 changes: 7 additions & 0 deletions
7
typescript/aws-codepipeline-ecs-lambda/assets/lambda-functions/events_handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { EventBridgeEvent, Context } from 'aws-lambda'; | ||
|
|
||
| export const handler = async (event: EventBridgeEvent<string, any>) => { | ||
| console.log('LogEvent'); | ||
| console.log('Received event:', JSON.stringify(event, null, 2)); | ||
| return 'Finished'; | ||
| }; |
18 changes: 18 additions & 0 deletions
18
typescript/aws-codepipeline-ecs-lambda/assets/lambda-functions/queue_message_handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { SQSEvent, SQSBatchResponse, SQSBatchItemFailure } from 'aws-lambda'; | ||
|
|
||
| export const handler = (event: SQSEvent): SQSBatchResponse | void => { | ||
| if (event) { | ||
| const batchItemFailures: SQSBatchItemFailure[] = []; | ||
| event?.Records.forEach(record => { | ||
| try { | ||
| // process record | ||
| } catch (err) { | ||
| batchItemFailures.push({ | ||
| itemIdentifier: record.messageId | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| return { batchItemFailures }; | ||
| } | ||
| }; |
19 changes: 19 additions & 0 deletions
19
typescript/aws-codepipeline-ecs-lambda/assets/lambda-functions/topic_message_handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { SNSEvent, SNSEventRecord } from 'aws-lambda'; | ||
|
|
||
| export const handler = async (event: SNSEvent) => { | ||
| for (const record of event.Records) { | ||
| await processMessageAsync(record); | ||
| } | ||
| console.info("done"); | ||
| }; | ||
|
|
||
| async function processMessageAsync(record: SNSEventRecord) { | ||
| try { | ||
| const message = JSON.stringify(record.Sns.Message); | ||
| console.log(`Processed message ${message}`); | ||
| await Promise.resolve(1); //Placeholder for actual async work | ||
| } catch (err) { | ||
| console.error("An error occurred"); | ||
| throw err; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| { | ||
| "app": "npx ts-node --prefer-ts-exts lib/app.ts", | ||
| "watch": { | ||
| "include": [ | ||
| "**" | ||
| ], | ||
| "exclude": [ | ||
| "README.md", | ||
| "cdk*.json", | ||
| "**/*.d.ts", | ||
| "**/*.js", | ||
| "tsconfig.json", | ||
| "package*.json", | ||
| "yarn.lock", | ||
| "node_modules", | ||
| "test" | ||
| ] | ||
| }, | ||
| "context": { | ||
| "@aws-cdk/aws-lambda:recognizeLayerVersion": true, | ||
| "@aws-cdk/core:checkSecretUsage": true, | ||
| "@aws-cdk/core:target-partitions": [ | ||
| "aws", | ||
| "aws-cn" | ||
| ], | ||
| "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
| "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
| "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, | ||
| "@aws-cdk/aws-iam:minimizePolicies": true, | ||
| "@aws-cdk/core:validateSnapshotRemovalPolicy": true, | ||
| "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, | ||
| "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, | ||
| "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, | ||
| "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, | ||
| "@aws-cdk/core:enablePartitionLiterals": true, | ||
| "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, | ||
| "@aws-cdk/aws-iam:standardizedServicePrincipals": true, | ||
| "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, | ||
| "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, | ||
| "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, | ||
| "@aws-cdk/aws-route53-patters:useCertificate": true, | ||
| "@aws-cdk/customresources:installLatestAwsSdkDefault": false, | ||
| "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, | ||
| "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, | ||
| "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, | ||
| "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, | ||
| "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, | ||
| "@aws-cdk/aws-redshift:columnId": true, | ||
| "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, | ||
| "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, | ||
| "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, | ||
| "@aws-cdk/aws-kms:aliasNameRef": true, | ||
| "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, | ||
| "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, | ||
| "@aws-cdk/aws-efs:denyAnonymousAccess": true, | ||
| "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, | ||
| "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, | ||
| "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, | ||
| "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, | ||
| "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, | ||
| "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, | ||
| "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, | ||
| "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true, | ||
| "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true, | ||
| "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true, | ||
| "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true, | ||
| "@aws-cdk/aws-eks:nodegroupNameAttribute": true, | ||
| "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true, | ||
| "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true, | ||
| "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env node | ||
| import 'source-map-support/register'; | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { pipelineStack } from './pipeline-stack'; | ||
|
|
||
| const app = new cdk.App(); | ||
| const env = { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION } | ||
| const pipelineAccountId = process.env.PIPELINE_ACCOUNT_ID || "111111111111"; // replace with your pipeline account id | ||
| const pipelineRegion = process.env.PIPELINE_REGION || "us-east-1"; // replace with your pipeline region | ||
| const githubOrg = process.env.GITHUB_ORG || "aws-6w8hnx"; // replace with your GitHub Org | ||
| const githubRepo = process.env.GITHUB_REPO || "aws-codepipeline-ecs-lambda"; // replace with your GitHub Repo | ||
| const githubBranch = process.env.GITHUB_BRANCH || "main"; // replace with your GitHub repo branch | ||
| const devEnv = process.env.DEV_ENV || "dev"; // replace with your environment | ||
| const devAccountId = process.env.DEV_ACCOUNT_ID || "222222222222"; // replace with your dev account id | ||
| const primaryRegion = process.env.PRIMARY_REGION || "us-west-2"; // replace with your primary region | ||
| const secondaryRegion = process.env.SECONDARY_REGION || "eu-west-1"; // replace with your secondary region | ||
|
|
||
|
|
||
| const pipeline_stack = new pipelineStack(app, 'aws-codepipeline-stack', { | ||
| env, | ||
| pipelineAccountId, | ||
| pipelineRegion, | ||
| githubOrg, | ||
| githubRepo, | ||
| githubBranch, | ||
| devEnv, | ||
| devAccountId, | ||
| primaryRegion, | ||
| secondaryRegion, | ||
| }); | ||
| cdk.Tags.of(pipeline_stack).add('managedBy', 'cdk'); | ||
| cdk.Tags.of(pipeline_stack).add('environment', 'dev'); | ||
|
|
||
| app.synth(); |
63 changes: 63 additions & 0 deletions
63
typescript/aws-codepipeline-ecs-lambda/lib/pipeline-stack.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { Construct } from 'constructs'; | ||
| import { CodePipeline, CodePipelineSource, ManualApprovalStep, ShellStep, Wave } from 'aws-cdk-lib/pipelines'; | ||
| import { pipelineAppStage } from './stage-app'; | ||
| import { PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||
|
|
||
| export interface pipelineProps extends cdk.StackProps { | ||
| readonly pipelineAccountId: string; | ||
| readonly pipelineRegion: string; | ||
| readonly githubOrg: string; | ||
| readonly githubRepo: string; | ||
| readonly githubBranch: string; | ||
| readonly devEnv: string; | ||
| readonly devAccountId: string; | ||
| readonly primaryRegion: string; | ||
| readonly secondaryRegion: string; | ||
| } | ||
|
|
||
| export class pipelineStack extends cdk.Stack { | ||
| constructor(scope: Construct, id: string, props: pipelineProps) { | ||
| super(scope, id, props); | ||
|
|
||
| const pipeline = new CodePipeline(this, 'pipeline', { | ||
| selfMutation: true, | ||
| crossAccountKeys: true, | ||
| reuseCrossRegionSupportStacks: true, | ||
| synth: new ShellStep('Synth', { | ||
| input: CodePipelineSource.connection(`${props.githubOrg}/${props.githubRepo}`, `${props.githubBranch}`,{ | ||
| // You need to replace the below code connection arn: | ||
| connectionArn: `arn:aws:codestar-connections:${props.pipelineRegion}:${props.pipelineAccountId}:connection/0ce75950-a29b-4ee4-a9d3-b0bad3b2c0a6` | ||
| }), | ||
| commands: [ | ||
| 'npm ci', | ||
| 'npm run build', | ||
| 'npx cdk synth' | ||
| ] | ||
| }), | ||
| synthCodeBuildDefaults: { | ||
| rolePolicy: [ | ||
| new PolicyStatement({ | ||
| resources: [ '*' ], | ||
| actions: [ 'ec2:DescribeAvailabilityZones' ], | ||
| }), | ||
| ]} | ||
| }); | ||
|
|
||
| const devStage = pipeline.addStage(new pipelineAppStage(this, `${props.devEnv}`, { | ||
| env: { account: `${props.pipelineAccountId}`, region: `${props.pipelineRegion}`} | ||
| })); | ||
| devStage.addPost(new ManualApprovalStep('approval')); | ||
|
|
||
| // add waves: | ||
| const devWave = pipeline.addWave(`${props.devEnv}Wave`); | ||
|
|
||
| devWave.addStage(new pipelineAppStage(this, `${props.devEnv}-${props.primaryRegion}`, { | ||
| env: { account: `${props.devAccountId}`, region: `${props.primaryRegion}`} | ||
| })); | ||
|
|
||
| devWave.addStage(new pipelineAppStage(this, `${props.devEnv}-${props.secondaryRegion}`, { | ||
| env: { account: `${props.devAccountId}`, region: `${props.secondaryRegion}`} | ||
| })); | ||
| } | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
typescript/aws-codepipeline-ecs-lambda/lib/stage-app-async-lambda-stack.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { Construct } from 'constructs'; | ||
| import * as events from 'aws-cdk-lib/aws-events'; | ||
| import * as eventsTargets from 'aws-cdk-lib/aws-events-targets'; | ||
| import * as sns from 'aws-cdk-lib/aws-sns'; | ||
| import * as sqs from 'aws-cdk-lib/aws-sqs'; | ||
| import { SnsEventSource, SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'; | ||
| import * as path from 'path'; | ||
| import { Function, Code, Runtime } from 'aws-cdk-lib/aws-lambda'; | ||
|
|
||
| export class asyncLambdaStack extends cdk.Stack { | ||
| constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
| super(scope, id, props); | ||
|
|
||
| // EventBridge event as an event source for a SNS topic and a SQS queue | ||
| const rule = new events.Rule(this, 'Rule', { | ||
| eventPattern: { | ||
| source: ['aws.ecs'] | ||
| } | ||
| }); | ||
|
|
||
| // Shared code asset | ||
| const code = Code.fromAsset(path.join(__dirname, '../assets/lambda-functions')); | ||
|
|
||
| // Lambda Function that will be invoked asynchronously when there is any event that matches the rule | ||
| const eventsFunction = new Function(this, 'EventFunction', { | ||
| runtime: Runtime.NODEJS_20_X, | ||
| code, | ||
| handler: 'events_handler.handler' | ||
| }); | ||
| const eventsDLQ = new sqs.Queue(this, 'LambdaDLQ'); | ||
| rule.addTarget(new eventsTargets.LambdaFunction(eventsFunction, { | ||
| deadLetterQueue: eventsDLQ, | ||
| maxEventAge: cdk.Duration.minutes(2), | ||
| retryAttempts: 2 | ||
| })); | ||
|
|
||
| // Lambda Function that will be invoked asynchronously by a SNS topic | ||
| const topic = new sns.Topic(this, 'Topic'); | ||
| rule.addTarget(new eventsTargets.SnsTopic(topic, { | ||
| deadLetterQueue: eventsDLQ, | ||
| maxEventAge: cdk.Duration.minutes(2), | ||
| retryAttempts: 2 | ||
| })); | ||
|
|
||
| const topicFunction = new Function(this, 'TopicLambdaFunction', { | ||
| runtime: Runtime.NODEJS_20_X, | ||
| code, | ||
| handler: 'topic_message_handler.handler' | ||
| }); | ||
| const topicDLQ = new sqs.Queue(this, 'TopicDLQ'); | ||
| topicFunction.addEventSource(new SnsEventSource(topic, { | ||
| deadLetterQueue: topicDLQ | ||
| })); | ||
|
|
||
| // Lambda Function that will be invoked asynchronously with the event source of a SQS queue | ||
| const queue = new sqs.Queue(this, 'JobQueue'); | ||
| rule.addTarget(new eventsTargets.SqsQueue(queue, { | ||
| deadLetterQueue: eventsDLQ, | ||
| maxEventAge: cdk.Duration.minutes(2), | ||
| retryAttempts: 2 | ||
| })); | ||
|
|
||
| const queueFunction = new Function(this, 'QueueLambdaFunction', { | ||
| runtime: Runtime.NODEJS_20_X, | ||
| code, | ||
| handler: 'queue_message_handler.handler' | ||
| }); | ||
| queueFunction.addEventSource(new SqsEventSource(queue, { | ||
| batchSize: 5, | ||
| maxBatchingWindow: cdk.Duration.seconds(5), | ||
| reportBatchItemFailures: true | ||
| })); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.