Convert Figma logo to code with AI

awslabs logoaws-solutions-constructs

The AWS Solutions Constructs Library is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions

1,216
247
1,216
67

Top Related Projects

11,501

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

Example projects using the AWS CDK

Quick Overview

AWS Solutions Constructs is an open-source library of CDK constructs that provides well-architected patterns for quickly building cloud applications. It offers pre-built components that combine multiple AWS services, following best practices for security, reliability, and operational excellence.

Pros

  • Accelerates development by providing pre-built, well-architected patterns
  • Ensures consistent implementation of AWS best practices across projects
  • Reduces the learning curve for complex AWS service integrations
  • Regularly updated to incorporate new AWS services and features

Cons

  • May introduce unnecessary complexity for simple projects
  • Limited flexibility compared to building custom CDK constructs
  • Requires familiarity with CDK and TypeScript/JavaScript
  • Some constructs may not cover all possible use cases or configurations

Code Examples

  1. Creating an API Gateway with Lambda backend:
import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda';

new ApiGatewayToLambda(this, 'ApiGatewayToLambdaPattern', {
  lambdaFunctionProps: {
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler',
    code: lambda.Code.fromAsset(`lambda`)
  }
});
  1. Setting up an S3 bucket with CloudFront distribution:
import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3';

new CloudFrontToS3(this, 'CloudFrontToS3Pattern', {
  bucketProps: {
    versioned: true
  },
  cloudFrontDistributionProps: {
    defaultBehavior: {
      compress: true
    }
  }
});
  1. Creating a VPC with public and private subnets:
import { Vpc } from '@aws-solutions-constructs/core';

new Vpc(this, 'VpcPattern', {
  maxAzs: 2,
  natGateways: 1
});

Getting Started

  1. Install the AWS CDK CLI:

    npm install -g aws-cdk
    
  2. Create a new CDK project:

    mkdir my-project && cd my-project
    cdk init app --language typescript
    
  3. Install AWS Solutions Constructs:

    npm install @aws-solutions-constructs/aws-apigateway-lambda
    
  4. Use the constructs in your CDK stack:

    import { Stack, StackProps } from 'aws-cdk-lib';
    import { Construct } from 'constructs';
    import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda';
    
    export class MyStack extends Stack {
      constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    
        new ApiGatewayToLambda(this, 'ApiGatewayToLambdaPattern', {
          lambdaFunctionProps: {
            runtime: lambda.Runtime.NODEJS_14_X,
            handler: 'index.handler',
            code: lambda.Code.fromAsset(`lambda`)
          }
        });
      }
    }
    

Competitor Comparisons

11,501

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code

Pros of aws-cdk

  • More flexible and customizable, allowing for fine-grained control over AWS resources
  • Supports multiple programming languages (TypeScript, JavaScript, Python, Java, C#)
  • Larger community and more extensive documentation

Cons of aws-cdk

  • Steeper learning curve, especially for those new to infrastructure as code
  • Requires more code to set up common patterns and best practices
  • May lead to inconsistencies across different teams or projects without proper governance

Code Comparison

aws-solutions-constructs:

import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda';

new ApiGatewayToLambda(this, 'ApiGatewayToLambda', {
  lambdaFunctionProps: {
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler',
    code: lambda.Code.fromAsset(`lambda`)
  }
});

aws-cdk:

import * as apigateway from '@aws-cdk/aws-apigateway';
import * as lambda from '@aws-cdk/aws-lambda';

const lambdaFunction = new lambda.Function(this, 'LambdaFunction', {
  runtime: lambda.Runtime.NODEJS_14_X,
  handler: 'index.handler',
  code: lambda.Code.fromAsset('lambda')
});

const api = new apigateway.RestApi(this, 'Api');
api.root.addMethod('GET', new apigateway.LambdaIntegration(lambdaFunction));
20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Pros of Pulumi

  • Multi-cloud support: Pulumi works with various cloud providers, not just AWS
  • Multiple programming language options: Supports Python, JavaScript, TypeScript, Go, and .NET
  • More flexible and extensible for complex infrastructure needs

Cons of Pulumi

  • Steeper learning curve for those familiar with declarative IaC tools
  • Requires more setup and configuration compared to AWS Solutions Constructs
  • May be overkill for simple AWS-only deployments

Code Comparison

AWS Solutions Constructs:

import * as constructs from '@aws-solutions-constructs/core';
import * as lambda from '@aws-cdk/aws-lambda';

new constructs.LambdaToSns(this, 'LambdaToSnsPattern', {
  lambdaFunctionProps: {
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler',
    code: lambda.Code.fromAsset(`lambda`)
  }
});

Pulumi:

import * as aws from "@pulumi/aws";

const lambdaFunction = new aws.lambda.Function("myFunction", {
    code: new pulumi.asset.AssetArchive({
        "index.js": new pulumi.asset.StringAsset("exports.handler = async (event) => { /* ... */ }")
    }),
    handler: "index.handler",
    runtime: "nodejs14.x"
});
42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

Pros of Terraform

  • Multi-cloud support: Works with various cloud providers, not limited to AWS
  • Larger ecosystem: Extensive provider and module marketplace
  • More mature and widely adopted in the industry

Cons of Terraform

  • Steeper learning curve for beginners
  • Requires manual state management
  • Less integrated with AWS-specific services and best practices

Code Comparison

Terraform:

resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  acl    = "private"
}

AWS Solutions Constructs:

import * as s3 from '@aws-cdk/aws-s3';

new s3.Bucket(this, 'MyBucket', {
  bucketName: 'my-bucket',
  encryption: s3.BucketEncryption.S3_MANAGED,
});

Key Differences

  • Terraform uses HCL (HashiCorp Configuration Language), while AWS Solutions Constructs uses TypeScript/JavaScript
  • AWS Solutions Constructs is built on top of AWS CDK, providing higher-level abstractions
  • Terraform requires explicit resource definitions, while AWS Solutions Constructs offers pre-configured, best-practice implementations

Use Cases

  • Terraform: Multi-cloud deployments, complex infrastructure setups
  • AWS Solutions Constructs: AWS-specific projects, rapid prototyping, and development of well-architected solutions

Community and Support

  • Terraform: Large community, extensive third-party modules
  • AWS Solutions Constructs: Growing community, direct AWS support and integration

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

Pros of Serverless

  • Framework-agnostic, supporting multiple cloud providers beyond AWS
  • Extensive plugin ecosystem for enhanced functionality
  • Simplified deployment and management of serverless applications

Cons of Serverless

  • Steeper learning curve for beginners compared to AWS Solutions Constructs
  • Less tightly integrated with AWS-specific services and best practices
  • May require additional configuration for complex AWS deployments

Code Comparison

Serverless:

service: my-service
provider:
  name: aws
  runtime: nodejs14.x
functions:
  hello:
    handler: handler.hello

AWS Solutions Constructs:

import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda';

new ApiGatewayToLambda(this, 'ApiGatewayToLambda', {
  lambdaFunctionProps: {
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler',
    code: lambda.Code.fromAsset(`lambda`)
  }
});

The Serverless Framework uses a YAML configuration file for defining services and functions, while AWS Solutions Constructs utilizes TypeScript/JavaScript with CDK constructs for infrastructure definition. Serverless offers a more concise syntax, while AWS Solutions Constructs provides stronger typing and integration with AWS services.

Example projects using the AWS CDK

Pros of aws-cdk-examples

  • Offers a wider variety of examples covering different AWS services and use cases
  • Provides more granular control over individual resources and configurations
  • Allows for more customization and flexibility in infrastructure design

Cons of aws-cdk-examples

  • Requires more in-depth knowledge of CDK and AWS services
  • May involve more complex code and setup for certain scenarios
  • Lacks pre-built, optimized patterns for common architectures

Code Comparison

aws-cdk-examples:

const bucket = new s3.Bucket(this, 'MyBucket', {
  versioned: true,
  encryption: s3.BucketEncryption.S3_MANAGED,
  removalPolicy: cdk.RemovalPolicy.DESTROY,
});

aws-solutions-constructs:

new s3.BucketEncryption(this, 'EncryptedBucket', {
  bucketName: 'my-encrypted-bucket',
  encryption: s3.BucketEncryption.KMS,
});

The aws-cdk-examples code provides more direct control over bucket properties, while aws-solutions-constructs offers a higher-level abstraction with pre-configured best practices for security and compliance.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

AWS Solutions Constructs

Browse Library:https://aws.amazon.com/solutions/constructs/patterns/
Reference Documentation:https://docs.aws.amazon.com/solutions/latest/constructs/

The AWS Solutions Constructs library is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions in code to create predictable and repeatable infrastructure. The goal of AWS Solutions Constructs is to accelerate the experience for developers to build solutions of any size using pattern-based definitions for their architecture.

The patterns defined in AWS Solutions Constructs are high level, multi-service abstractions of AWS CDK constructs that have default configurations based on well-architected best practices. The library is organized into logical modules using object-oriented techniques to create each architectural pattern model.

CDK Versions

AWS Solutions Constructs and the AWS CDK are independent teams and have different release schedules. Each release of AWS Solutions Constructs is built against a specific version of the AWS CDK. The CHANGELOG.md file lists the CDK version associated with each AWS Solutions Constructs release. For instance, AWS Solutions Constructs v2.39.0 was built against AWS CDK v2.76.0. This means that to use AWS Solutions Constructs v2.39.0, your application must include AWS CDK v2.76.0 or later. You can continue to use the latest AWS CDK versions and upgrade the your AWS Solutions Constructs version when new releases become available.

Modules

The AWS Solutions Constructs library is organized into several modules. They are named like this:

  • aws-xxx: well architected pattern package for the indicated services. This package will contain constructs that contain multiple AWS CDK service modules to configure the given pattern.
  • xxx: packages that don't start "aws-" are core modules that are used to configure best practice defaults for services used within the pattern library. They are not intended to be accessed directly.

Module Contents

Modules contain the following types:

  • Patterns - All higher-level, multi-services constructs in this library.
  • Other Types - All non-construct classes, interfaces, structs and enums that exist to support the patterns.

Patterns take a set of (input) properties in their constructor; the set of properties (and which ones are required) can be seen on a pattern's documentation page.

The pattern's documentation page also lists the available methods to call and the properties which can be used to retrieve information about the pattern after it has been instantiated.

Sample Use Cases

This library includes a collection of functional use case implementations to demonstrate the usage of AWS Solutions Constructs architectural patterns. These can be used in the same way as architectural patterns, and can be conceptualized as an additional "higher-level" abstraction of those patterns. The following use cases are provided as functional examples:


© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

NPM DownloadsLast 30 Days