Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@aws-cdk/aws-cloudformation
Advanced tools
@aws-cdk/aws-cloudformation is an AWS Cloud Development Kit (CDK) module that allows you to define AWS CloudFormation templates using TypeScript or JavaScript. It provides a high-level, object-oriented abstraction to define AWS resources and manage their lifecycle.
Creating a CloudFormation Stack
This code sample demonstrates how to create a CloudFormation stack using the @aws-cdk/aws-cloudformation package. It defines a nested stack with a template URL and parameters.
const cdk = require('@aws-cdk/core');
const cfn = require('@aws-cdk/aws-cloudformation');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
new cfn.CfnStack(this, 'MyNestedStack', {
templateUrl: 'https://s3.amazonaws.com/my-bucket/my-template.json',
parameters: {
MyParameter: 'ParameterValue'
}
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
app.synth();
Custom Resources
This code sample demonstrates how to create a custom resource using the @aws-cdk/aws-cloudformation package. It defines a custom resource with a service token and properties.
const cdk = require('@aws-cdk/core');
const cfn = require('@aws-cdk/aws-cloudformation');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
new cfn.CfnCustomResource(this, 'MyCustomResource', {
serviceToken: 'arn:aws:lambda:region:account-id:function:function-name',
properties: {
MyProperty: 'PropertyValue'
}
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
app.synth();
Wait Conditions
This code sample demonstrates how to create a wait condition using the @aws-cdk/aws-cloudformation package. It defines a wait condition handle and a wait condition with a timeout and count.
const cdk = require('@aws-cdk/core');
const cfn = require('@aws-cdk/aws-cloudformation');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const waitHandle = new cfn.CfnWaitConditionHandle(this, 'MyWaitHandle');
new cfn.CfnWaitCondition(this, 'MyWaitCondition', {
handle: waitHandle.ref,
timeout: '300',
count: 1
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
app.synth();
The aws-sdk package is the official AWS SDK for JavaScript, which allows you to interact with AWS services directly. Unlike @aws-cdk/aws-cloudformation, which provides a high-level abstraction for defining CloudFormation templates, aws-sdk provides low-level APIs to interact with AWS services, including CloudFormation.
The serverless package is a framework for building and deploying serverless applications on AWS and other cloud providers. It abstracts away much of the complexity of managing infrastructure, similar to @aws-cdk/aws-cloudformation, but focuses on serverless architectures and provides a different set of abstractions and tools.
Pulumi is an infrastructure as code tool that allows you to define cloud resources using general-purpose programming languages. It is similar to @aws-cdk/aws-cloudformation in that it provides high-level abstractions for defining cloud infrastructure, but it supports multiple cloud providers and languages beyond just AWS and TypeScript/JavaScript.
This module is part of the AWS Cloud Development Kit project.
Custom Resources are CloudFormation resources that are implemented by arbitrary user code. They can do arbitrary lookups or modifications during a CloudFormation synthesis run.
You will typically use Lambda to implement a Construct implemented as a
Custom Resource (though SNS topics can be used as well). Your Lambda function
will be sent a CREATE
, UPDATE
or DELETE
message, depending on the
CloudFormation life cycle. It will perform whatever actions it needs to, and
then return any number of output values which will be available as attributes
of your Construct. In turn, those can be used as input to other Constructs in
your model.
In general, consumers of your Construct will not need to care whether it is implemented in term of other CloudFormation resources or as a custom resource.
Note: when implementing your Custom Resource using a Lambda, use
a SingletonLambda
so that even if your custom resource is instantiated
multiple times, the Lambda will only get uploaded once.
The following shows an example of a declaring Custom Resource that copies files into an S3 bucket during deployment (the implementation of the actual Lambda handler is elided for brevity).
The aws-cdk-examples repository has examples for adding custom resources.
See the following section of the docs on details to write Custom Resources:
Nested stacks are stacks created as part of other stacks. You create a nested stack within another stack by using the NestedStack
construct.
As your infrastructure grows, common patterns can emerge in which you declare the same components in multiple templates. You can separate out these common components and create dedicated templates for them. Then use the resource in your template to reference other templates, creating nested stacks.
For example, assume that you have a load balancer configuration that you use for most of your stacks. Instead of copying and pasting the same configurations into your templates, you can create a dedicated template for the load balancer. Then, you just use the resource to reference that template from within other templates.
The following example will define a single top-level stack that contains two nested stacks: each one with a single Amazon S3 bucket:
import { Stack, Construct, StackProps } from '@aws-cdk/core';
import cfn = require('@aws-cdk/aws-cloudformation');
import s3 = require('@aws-cdk/aws-s3');
class MyNestedStack extends cfn.NestedStack {
constructor(scope: Construct, id: string, props?: cfn.NestedStackProps) {
super(scope, id, props);
new s3.Bucket(this, 'NestedBucket');
}
}
class MyParentStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new MyNestedStack(this, 'Nested1');
new MyNestedStack(this, 'Nested2');
}
}
Resources references across nested/parent boundaries (even with multiple levels of nesting) will be wired by the AWS CDK
through CloudFormation parameters and outputs. When a resource from a parent stack is referenced by a nested stack,
a CloudFormation parameter will automatically be added to the nested stack and assigned from the parent; when a resource
from a nested stack is referenced by a parent stack, a CloudFormation output will be automatically be added to the
nested stack and referenced using Fn::GetAtt "Outputs.Xxx"
from the parent.
Nested stacks also support the use of Docker image and file assets.
1.25.0 (2020-02-18)
MappingTemplate.dynamoDbPutItem()
to accept
PrimaryKey
and AttributeValues
, which allow configuring the primary
key and to project an object to a set of attribute values.--wait
option. (#6276) (1811e00), closes /github.com/helm/helm/blob/b63822ed12de1badbb61736d2f7ea4e756ef757d/pkg/action/install.go#L52-L55FAQs
The CDK Construct Library for AWS::CloudFormation
The npm package @aws-cdk/aws-cloudformation receives a total of 70,349 weekly downloads. As such, @aws-cdk/aws-cloudformation popularity was classified as popular.
We found that @aws-cdk/aws-cloudformation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.