AWS SDK for .NET
Developer Guide

This documentation is for version 2.0 of the AWS SDK for .NET. For the latest version, see the AWS SDK for .NET Developer Guide for version 3.

AWS CloudFormation Programming with the AWS SDK for .NET

The AWS SDK for .NET supports AWS CloudFormation, which creates and provision AWS infrastructure deployments predictably and repeatedly. For more information, see CloudFormation Getting Started Guide.

The following information introduces you to the CloudFormation programming models in the the SDK.

Programming Models#

The the SDK provides two programming models for working with CloudFormation. These programming models are known as the low-level and resource models. The following information describes these models, how to use them, and why you would want to use them.

Low-Level APIs#

The the SDK provides low-level APIs for programming with CloudFormation. These low-level APIs typically consist of sets of matching request-and-response objects that correspond to HTTP-based API calls focusing on their corresponding service-level constructs.

The following example shows how to use the low-level APIs to list accessible resources in CloudFormation:

// using Amazon.CloudFormation;
// using Amazon.CloudFormation.Model;

var client = new AmazonCloudFormationClient();
var request = new DescribeStacksRequest();
var response = client.DescribeStacks(request);

foreach (var stack in response.Stacks)
{
  Console.WriteLine("Stack: {0}", stack.StackName);
  Console.WriteLine("  Status: {0}", stack.StackStatus);
  Console.WriteLine("  Created: {0}", stack.CreationTime);

  var ps = stack.Parameters;

  if (ps.Any())
  {
    Console.WriteLine("  Parameters:");

    foreach (var p in ps)
    {
      Console.WriteLine("    {0} = {1}", 
        p.ParameterKey, p.ParameterValue);
    }

  }
  
}

For related API reference information, see Amazon.CloudFormation and Amazon.CloudFormation.Model in the sdk-net-api-v2.

Resource APIs#

The the SDK provides the AWS Resource APIs for .NET for programming with CloudFormation. These resource APIs provide a resource-level programming model that enables you to write code to work more directly with CloudFormation resources as compared to their low-level API counterparts. (For more information about the AWS Resource APIs for .NET, including how to download and reference these resource APIs, see Programming with the AWS Resource APIs for .NET.)

The following example shows how to use the AWS Resource APIs for .NET to list accessible resources in CloudFormation:

// using Amazon.CloudFormation.Resources;

var cf = new CloudFormation();

foreach (var stack in cf.GetStacks())
{
  Console.WriteLine("Stack: {0}", stack.Name);
  Console.WriteLine("  Status: {0}", stack.StackStatus);
  Console.WriteLine("  Created: {0}", stack.CreationTime);

  var ps = stack.Parameters;

  if (ps.Any())
  {
    Console.WriteLine("  Parameters:");

    foreach (var p in ps)
    {
      Console.WriteLine("    {0} = {1}", 
        p.ParameterKey, p.ParameterValue);
    }

  }

}

For related API reference information, see Amazon.CloudFormation.Resources.

On this page: