Introduction
AWS Solutions Constructs is an open-source extension of the AWS Cloud Development Kit (CDK) that provides multi-service, well-architected patterns for rapidly defining solutions in code in order to create predictable and repeatable infrastructure. The goal is to help developers build solutions of any size faster by using pattern-based definitions for their architecture.
In other words, it is a method of creating architecture in an opinionated manner while utilising AWS best practices. It is also an excellent presentation of the AWS CDK capabilities (most notably reusability and modularity), as well as a model example of how it can be used.
AWS Solution Constructs Hierarchy
The hierarchy of the AWS Solution Constructs can be classified into three parts.
AWS Cloudformation
The hierarchy begins with the creation of the Infrastructure as a Service (IaS) service on the AWS cloud. Using declarative YAML or JSON templates, you can define entire cloud architectures. These templates are incredibly powerful mechanisms for building infrastructure as code.
Example code defining Cloudformation
"aws_queue 1234567": {
"Type": "AWS:: SQS::Queue",
"Properties": {
"MaximumMessageSize": 3416,
"QueueName": "aws-demo-queue"
}
}
AWS Cloud Development Kit (CDK)
The AWS Cloud Development Kit (AWS CDK) is a free and open-source software development framework that allows users to define cloud application resources in familiar programming languages. AWS CDK models your applications using the familiarity and expressive power of programming languages. It provides high-level components known as constructs that preconfigure cloud resources with proven defaults, allowing you to easily build cloud applications.
The AWS Cloud Development Kit (AWS CDK) adds an abstraction layer over confirmation templates, allowing you to define your infrastructure using conventional programming languages rather than declarative markup.
Using the CDK, our code is changes to:
new sqs.Queue (this, 'aws_queue', {
queueName: 'aws_queue',
maxMessageSizeBytes: 3416,
});
AWS Solutions Constructs
AWS solutions constructs are implementations of common architectural patterns that can be plugged into your CDK stacks on their own or in conjunction with other solutions constructs. They are all built on top of the CDK, which in turn is built on top of cloud formation. Constructs enable you to combine pre-built, well-architected patterns and use cases that perform common actions in a scalable and secure manner using cloud services.
Below is the example of AWS-SQS lambda, a construct that deploys an SQS-Queue along with a lambda function that’s invoked whenever a message is stored in the queue.
new SqsToLambda (this, 'SqsToLambdaPattern',{
lambdaFunctionProps: {
runtime: lambda.Runtime. NODEJS_10_X,
handler: 'function.handler',
code: lambda.Code.fromAsset (`lambda)
},
queue Props: {
maxMessageSizeBytes: 3416,
queueName: 'aws_queue'
});