Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
aws-cdk-lib
Advanced tools
The aws-cdk-lib package is the primary library for the AWS Cloud Development Kit (AWS CDK), which is a software development framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation. It provides high-level components called constructs that preconfigure cloud resources with sensible defaults, making it easier to build cloud applications.
Defining Infrastructure
This feature allows you to define AWS infrastructure using high-level constructs. In the code sample, a new S3 bucket is defined within a stack.
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyFirstStack');
new s3.Bucket(stack, 'MyFirstBucket', {
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
Configuring IAM Policies
This feature enables the creation and configuration of IAM roles and policies. The code sample creates an IAM role and grants it permissions to perform all actions on S3 resources.
const role = new iam.Role(stack, 'MyRole', {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
role.addToPolicy(new iam.PolicyStatement({
actions: ['s3:*'],
resources: ['*'],
}));
Creating Serverless Functions
This feature is used to define AWS Lambda functions. The code sample shows how to create a new Lambda function with Node.js runtime and specifies the source code directory.
new lambda.Function(stack, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda'),
});
Setting up API Gateway
This feature allows you to set up an API Gateway to create RESTful APIs. The code sample demonstrates how to create an API Gateway and integrate it with a Lambda function.
const api = new apigateway.RestApi(stack, 'MyApi', {
restApiName: 'My Service',
});
const getWidgetsIntegration = new apigateway.LambdaIntegration(myLambdaFunction);
api.root.addMethod('GET', getWidgetsIntegration);
The Serverless Framework is an open-source CLI for building and deploying serverless applications. It offers a similar experience to AWS CDK but is cloud-agnostic, supporting multiple cloud providers. It uses a configuration file to define the services and resources.
Terraform by HashiCorp is an infrastructure as code tool that allows you to define both cloud and on-premises resources with a declarative configuration language. It is also cloud-agnostic and uses its own state management for keeping track of the infrastructure.
Pulumi is an infrastructure as code tool that allows you to define infrastructure using general-purpose programming languages such as JavaScript, TypeScript, Python, Go, and .NET. It supports multiple cloud providers and offers a more developer-centric experience compared to AWS CDK.
The AWS CDK construct library provides APIs to define your CDK application and add CDK constructs to the application.
When upgrading from CDK 1.x, remove all dependencies to individual CDK packages from your dependencies file and follow the rest of the sections.
To use this package, you need to declare this package and the constructs
package as
dependencies.
According to the kind of project you are developing:
devDependencies
and peerDependencies
sections.dependencies
section only.You can use a classic import to get access to each service namespaces:
import { core, aws_s3 as s3 } from 'aws-cdk-lib';
const app = new core.App();
const stack = new core.Stack(app, 'TestStack');
new s3.Bucket(stack, 'TestBucket');
Alternatively, you can use "barrel" imports:
import { App, Stack } from 'aws-cdk-lib';
import { Bucket } from 'aws-cdk-lib/aws-s3';
const app = new App();
const stack = new Stack(app, 'TestStack');
new Bucket(stack, 'TestBucket');
FAQs
Version 2 of the AWS Cloud Development Kit library
The npm package aws-cdk-lib receives a total of 1,112,530 weekly downloads. As such, aws-cdk-lib popularity was classified as popular.
We found that aws-cdk-lib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.