How do I choose between AWS Native, AWS Classic, and AWSx providers?
Understanding AWS Providers in Pulumi
Pulumi offers multiple ways to manage AWS resources, each with different levels of abstraction and integration. Here’s a breakdown of the three main AWS providers you might encounter:
AWS Classic (
@pulumi/aws
):- This is the most commonly used provider for managing AWS resources with Pulumi.
- It provides a direct mapping to the AWS API, allowing you to manage a wide range of AWS services.
- Suitable for users who need fine-grained control over AWS resources.
AWS Native (
@pulumi/aws-native
):- This provider is in preview and offers a more direct integration with AWS CloudFormation.
- It allows you to use the same resource model as CloudFormation, which can be beneficial if you’re familiar with CloudFormation templates.
- AWS Native is designed to provide quicker access to new AWS features as they become available.
AWSx (
@pulumi/awsx
):- AWSx provides higher-level abstractions for AWS resources, making it easier to work with complex setups.
- It includes components like
Vpc
,Cluster
, andFargateService
that simplify common patterns. - Ideal for users who want to get started quickly with best practices built-in.
Example Program Using AWSx
Let’s create a simple VPC using the AWSx provider to demonstrate how it simplifies resource management. This example will set up a VPC with public and private subnets.
import * as pulumi from "@pulumi/pulumi";
import * as awsx from "@pulumi/awsx";
// Create a new VPC with the default configuration
const vpc = new awsx.ec2.Vpc("my-vpc", {
subnetSpecs: [
{
type: awsx.ec2.SubnetType.Public,
cidrBlocks: ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"],
},
{
type: awsx.ec2.SubnetType.Private,
cidrBlocks: ["10.0.3.0/24", "10.0.4.0/24", "10.0.5.0/24"],
}
],
});
// Export the VPC ID and subnet IDs
export const vpcId = vpc.vpcId;
export const publicSubnetIds = vpc.publicSubnetIds;
export const privateSubnetIds = vpc.privateSubnetIds;
Explanation
Importing Modules:
- We import
pulumi
for the Pulumi SDK andawsx
for the higher-level AWS components.
- We import
Creating a VPC:
- We use
awsx.ec2.Vpc
to create a new VPC. This automatically sets up subnets, route tables, and other necessary resources. - The configuration specifies that we want both public and private subnets.
- We use
Exporting Outputs:
- We export the VPC ID and the IDs of the public and private subnets. These outputs can be used in other parts of your Pulumi program or for debugging.
Conclusion
Using AWSx, you can quickly set up complex AWS infrastructure with sensible defaults and best practices. AWS Classic offers more control, while AWS Native provides a CloudFormation-like experience. Choose the provider that best fits your needs and familiarity with AWS services.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.