AWS Solutions Constructs

repository·main·Indexed 23 days ago

https://github.com/awslabs/aws-solutions-constructs

An open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides high-level, multi-service architectural patterns. It offers pre-configured constructs based on AWS best practices to help developers build well-architected, repeatable infrastructure. The library includes pattern modules for specific use cases, such as aws-lambda-textract and LambdaToTranscribe, and core modules for internal logic.

Tokens
246.6K
Snippets
298
Records
1K
Agent score
72%

What's inside aws-solutions-constructs

  1. Overview of the aws-lambda-textract module

    main

    The aws-lambda-textract construct implements an AWS Lambda function integrated with the Amazon Textract service.

    Key Capabilities:

    • Lambda & Textract Integration: Provides a pre-configured Lambda function designed to interact with Amazon Textract.
    • Asynchronous Document Analysis: For asynchronous workflows, the construct can optionally provision:
      • A source S3 bucket for uploading documents.
      • A destination S3 bucket for storing analysis results.
      • IAM Permissions: Automatically configures the necessary permissions for the Lambda function to access the S3 buckets and the Amazon Textract service.
  2. What is AWS Solutions Constructs?

    main
    AWS Solutions Constructs is an open-source extension of the AWS Cloud Development Kit (AWS CDK). It provides multi-service, well-architected patterns that allow developers to define complex infrastructure solutions using code. Instead of manually configuring individual AWS services, you use these pattern-based definitions to create predictable, repeatable, and scalable infrastructure.
  3. Implement an SQS queue connected to an AWS Lambda function

    main

    The aws-sqs-lambda module provides a pattern to deploy an Amazon SQS queue that triggers an AWS Lambda function. It includes built-in best practices such as dead-letter queue (DLQ) support, server-side encryption, and limited-privilege IAM roles.

    Package Information

    • TypeScript: @aws-solutions-constructs/aws-sqs-lambda
    • Python: aws_solutions_constructs.aws_sqs_lambda
    • Java: software.amazon.awsconstructs.services.sqslambda
    import { Construct } from 'constructs';
    import { Stack, StackProps } from 'aws-cdk-lib';
    import { SqsToLambda, SqsToLambdaProps } from "@aws-solutions-constructs/aws-sqs-lambda";
    import * as lambda from 'aws-cdk-lib/aws-lambda';
    
    new SqsToLambda(this, 'SqsToLambdaPattern', {
      lambdaFunctionProps: {
        runtime: lambda.Runtime.NODEJS_22_X,
        handler: 'index.handler',
        code: lambda.Code.fromAsset(`lambda`)
      }
    });
  4. Implement an AWS Fargate service that writes to Amazon SQS

    main

    The FargateToSqs construct implements an AWS Fargate service capable of writing messages to an Amazon SQS queue. It handles the setup of the Fargate service, the SQS queue, IAM permissions, and environment variables for the container.

    Stability Warning

    This module is currently Experimental. All classes are under active development and are not subject to Semantic Versioning. You may need to update your source code when upgrading to newer versions.

    Package Information

    • TypeScript: @aws-solutions-constructs/aws-fargate-sqs
    • Python: aws_solutions_constructs.aws_fargate_sqs
    • Java: software.amazon.awsconstructs.services.fargatesqs
    // TypeScript Example
    import { Construct } from 'constructs';
    import { Stack, StackProps } from 'aws-cdk-lib';
    import { FargateToSqs, FargateToSqsProps } from '@aws-solutions-constructs/aws-fargate-sqs';
    
    const constructProps: FargateToSqsProps = {
        publicApi: true,
        ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo"
    };
    
    new FargateToSqs(this, 'test-construct', constructProps);
  5. Implement an Amazon API Gateway WebSocket connected to an Amazon SQS queue

    main

    The aws-apigatewayv2websocket-sqs construct implements a pattern where an Amazon API Gateway WebSocket is connected to an Amazon SQS queue. This allows WebSocket messages to be routed directly into an SQS queue for downstream processing.

    Package Information

    • TypeScript: @aws-solutions-constructs/aws-apigatewayv2websocket-sqs
    • Python: aws_solutions_constructs.aws_apigateway_sqs
    • Java: software.amazon.awsconstructs.services.apigatewaysqs
    import { Construct } from "constructs";
    import { Stack, StackProps } from "aws-cdk-lib";
    import {
        ApiGatewayV2WebSocketToSqs,
        ApiGatewayV2WebSocketToSqsProps,
    } from "@aws-solutions-constructs/aws-apigatewayv2websocket-sqs";
    import { WebSocketLambdaAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
    
    const authorizer = new WebSocketLambdaAuthorizer('Authorizer', authHandler);
    
    new ApiGatewayV2WebSocketToSqs(this, "ApiGatewayV2WebSocketToSqsPattern", {
        webSocketApiProps: {
            connectRouteOptions: {
                integration: new WebSocketLambdaIntegration("ConnectIntegration", connectLambda),
                authorizer: authorizer,
            },
            disconnectRouteOptions: {
                integration: new WebSocketLambdaIntegration("DisconnectIntegration", disconnectLambda),
            },
        },
        createDefaultRoute: true
    });
  6. Implement an AWS Lambda function connected to an Amazon SNS topic

    main

    The aws-lambda-sns module provides a pattern to deploy an AWS Lambda function that is triggered by or connected to an Amazon SNS topic. It handles the necessary IAM permissions, environment variables, and networking (VPC/Interface Endpoints) automatically.

    Package Information

    • TypeScript: @aws-solutions-constructs/aws-lambda-sns
    • Python: aws_solutions_constructs.aws_lambda_sns
    • Java: software.amazon.awsconstructs.services.lambdasns
    import { LambdaToSns, LambdaToSnsProps } from "@aws-solutions-constructs/aws-lambda-sns";
    import * as lambda from 'aws-cdk-lib/aws-lambda';
    
    new LambdaToSns(this, 'test-lambda-sns', {
      lambdaFunctionProps: {
        runtime: lambda.Runtime.NODEJS_22_X,
        handler: 'index.handler',
        code: lambda.Code.fromAsset(`lambda`)
      }
    });
  7. Implement an Amazon EventBridge rule to send data to Amazon Kinesis Data Stream

    main

    The aws-eventbridge-kinesisstreams module implements a pattern where an Amazon EventBridge rule is configured to publish data directly to an Amazon Kinesis Data Stream. By default, the construct enables server-side encryption for the Kinesis stream using an AWS Managed KMS Key and configures a least-privilege IAM role for the EventBridge rule.

    Package Information

    • TypeScript: @aws-solutions-constructs/aws-eventbridge-kinesisstreams
    • Python: aws_solutions_constructs.aws_eventbridge_kinesis_streams
    • Java: software.amazon.awsconstructs.services.eventbridgekinesisstreams

    Note: This module is currently marked as Experimental. Classes are under active development and may undergo non-backward compatible changes or removal without following Semantic Versioning.

    import { Construct } from 'constructs';
    import { Stack, StackProps, Duration } from 'aws-cdk-lib';
    import { EventbridgeToKinesisStreams, EventbridgeToKinesisStreamsProps } from "@aws-solutions-constructs/aws-eventbridge-kinesisstreams";
    import * as events from 'aws-cdk-lib/aws-events';
    
    const constructProps: EventbridgeToKinesisStreamsProps = {
      eventRuleProps: {
        schedule: events.Schedule.rate(Duration.minutes(5)),
      }
    };
    
    new EventbridgeToKinesisStreams(this, 'test-eventbridge-kinesis-streams', constructProps);
  8. Implement an AWS Fargate service that executes an AWS Step Functions state machine

    main

    The FargateToStepfunctions construct automates the deployment of an AWS Fargate service configured to trigger an AWS Step Functions state machine. It handles the creation of the Fargate service, the state machine, necessary IAM permissions for the container to start state machine executions, and adds an Interface Endpoint to the VPC for Step Functions. It also adds an environment variable to the container containing the state machine's ARN.

    Stability Note: This module is currently Experimental. All classes are under active development and are not subject to Semantic Versioning. You may need to update your code when upgrading to newer versions.

    import { Construct } from 'constructs';
    import { Stack, StackProps } from 'aws-cdk-lib';
    import { FargateToStepfunctions, FargateToStepfunctionsProps } from '@aws-solutions-constructs/aws-fargate-stepfunctions';
    import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';
    
    const startState = new stepfunctions.Pass(this, 'StartState');
    
    const constructProps: FargateToStepfunctionsProps = {
      publicApi: true,
      ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo",
      stateMachineProps: {
          definition: startState
        }
    };
    
    new FargateToStepfunctions(this, 'test-construct', constructProps);
  9. Implement an Amazon EventBridge rule and AWS SQS Queue

    main

    The aws-eventbridge-sqs construct automates the setup of an Amazon EventBridge rule that targets an AWS SQS queue. By default, it implements security best practices such as:

    • Granting least-privilege permissions to the EventBridge rule to publish to the SQS queue.
    • Deploying an SQS dead-letter queue (DLQ) for the source SQS queue.
    • Enabling server-side encryption for the source SQS queue using a Customer Managed KMS Key.
    • Enforcing encryption of data in transit.

    Package Information

    • Python: aws_solutions_constructs.aws_eventbridge_sqs
    • Typescript: @aws-solutions-constructs/aws-eventbridge-sqs
    • Java: software.amazon.awsconstructs.services.eventbridgesqs
    import { EventbridgeToSqsProps, EventbridgeToSqs } from "@aws-solutions-constructs/aws-eventbridge-sqs";
    
    const constructProps: EventbridgeToSqsProps = {
      eventRuleProps: {
        schedule: events.Schedule.rate(Duration.minutes(5))
      }
    };
    
    const constructStack = new EventbridgeToSqs(this, 'test-construct', constructProps);
  10. Implement an AWS Lambda function connected to Amazon EventBridge

    main

    The aws-lambda-eventbridge module provides a construct that implements an AWS Lambda function with the necessary permissions and environment configuration to send events to an Amazon EventBridge bus.

    By default, the construct:

    • Configures a limited-privilege IAM role for the Lambda function.
    • Enables X-Ray tracing.
    • Sets the EVENTBUS_NAME environment variable so the Lambda function knows which bus to target.
    • Enables connection reuse (Keep-Alive) for Node.js runtimes.
    • Sets AWS_NODEJS_CONNECTION_REUSE_ENABLED for Node.js 10.x and higher.

    You can choose to use an existing Lambda function, a custom EventBus, or deploy the pattern into a new or existing VPC.

    import { LambdaToEventbridge, LambdaToEventbridgeProps } from "@aws-solutions-constructs/aws-lambda-eventbridge";
    import * as lambda from 'aws-cdk-lib/aws-lambda';
    
    new LambdaToEventbridge(this, 'LambdaToEventbridgePattern', {
      lambdaFunctionProps: {
        runtime: lambda.Runtime.NODEJS_22_X,
        handler: 'index.handler',
        code: lambda.Code.fromAsset(`lambda`)
      }
    });
  11. Implement DynamoDB Streams to Step Functions via EventBridge Pipes

    main

    The DynamoDBStreamsToPipesToStepfunctions construct implements a pattern where an Amazon DynamoDB table with a stream triggers an AWS Step Functions state machine using an Amazon EventBridge Pipe.

    Stability Note: This construct is currently marked as Experimental.

    Package Names by Language:

    • TypeScript: @aws-solutions-constructs/aws-dynamodbstreams-pipes-stepfunctions
    • Python: aws_solutions_constructs.aws_dynamodbstreams_pipes_stepfunctions
    • Java: software.amazon.awsconstructs.services.dynamodbstreamspipesstepfunctions
    import { Construct } from 'constructs';
    import { Stack, StackProps } from 'aws-cdk-lib';
    import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
    import { DynamoDBStreamsToPipesToStepfunctions, DynamoDBStreamsToPipesToStepfunctionsProps } from "@aws-solutions-constructs/aws-dynamodbstreams-pipes-stepfunctions";
    
    const startState = new sfn.Pass(this, 'StartState');
    
    new DynamoDBStreamsToPipesToStepfunctions(this, 'DynamoDBStreamsToPipesToStepfunctionsPattern', {
          stateMachineProps: {
            definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(this, 'Pass'))),
          }
        });
  12. Deploy an AWS Lambda function connected to Amazon ElastiCache Memcached

    main

    The aws-lambda-elasticachememcached construct implements a pattern where an AWS Lambda function is connected to an Amazon ElastiCache Memcached cluster. By default, it creates a multi-node, cross-AZ cluster with 2 cache.t3.medium nodes and configures the Lambda function with limited privilege IAM roles, X-Ray tracing, and connection reuse (Keep-Alive) for Node.js runtimes. It also sets the CACHE_ENDPOINT environment variable in the Lambda function to point to the cluster.

    import { Construct } from 'constructs';
    import { Stack, StackProps } from 'aws-cdk-lib';
    import { LambdaToElasticachememcached } from '@aws-solutions-constructs/aws-lambda-elasticachememcached';
    import * as lambda from 'aws-cdk-lib/aws-lambda';
    
    new LambdaToElasticachememcached(this, 'LambdaToElasticachememcachedPattern', {
        lambdaFunctionProps: {
            runtime: lambda.Runtime.NODEJS_22_X,
            handler: 'index.handler',
            code: lambda.Code.fromAsset(`lambda`)
        }
    });