AWSSDK.CloudFormation (for AWS CloudFormation)

✦ The Fourth SDK we are going to talk about is AWSSDK.CloudFormation.

First of all, let’s have a brief about Amazon CloudFormation in AWS…

➽What is Amazon CloudFormation?

☞ AWS CloudFormation is a service that helps you model and set up …

✦ The Fourth SDK we are going to talk about is AWSSDK.CloudFormation.

First of all, let’s have a brief about Amazon CloudFormation in AWS…



➽What is Amazon CloudFormation?

AWS CloudFormation is a service that helps you model and set up your AWS resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS.
☞ You create a template that describes all the AWS resources that you want (like Amazon EC2 instances or Amazon RDS DB instances), and CloudFormation takes care of provisioning and configuring those resources for you.
☞ You don’t need to individually create and configure AWS resources and figure out what’s dependent on what; CloudFormation handles that.
☞ Read more about Amazon CloudFormation



➽Installing AWSSDK.CloudFormation :

AWSSDK.CloudFormation is installed mainly from Nuget
☞There is 3 ways to install AWSSDK.CloudFormation, they are the same as installing AWSSDK.S3 from Part 1 of this series
☞let’s use the easiest one, from Package Manager Console by using the Install-Package command.

PM> Install-Package AWSSDK.CloudFormation

? Second step is to connect to our AWS account using __ Access keys (Access Key ID and Secret Access Key)__, this was explained before briefly in the first article under (Get AWS Access keys)

✦ The AWS SDK for .NET provides APIs for AWS CloudFormation clients. The APIs enable you to work with AWS CloudFormation features such as templates and stacks.
✦ The example uses the low-level API. The application takes no arguments, but simply gathers information for all stacks that are accessible to the user’s credentials and then displays information
about those stacks.

using System;
using System.Threading.Tasks;
using Amazon.CloudFormation;
using Amazon.CloudFormation.Model;

namespace CFNListResources
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Create the CloudFormation client
            var cfnClient = new AmazonCloudFormationClient();

            // List the resources for each stack
            await ListResources(cfnClient, await cfnClient.DescribeStacksAsync());
        }

        //
        // Method to list stack resources and other information
        private static async Task ListResources(
          IAmazonCloudFormation cfnClient, DescribeStacksResponse responseDescribeStacks)
        {
            Console.WriteLine("Getting CloudFormation stack information...");

            foreach (Stack stack in responseDescribeStacks.Stacks)
            {
                // Basic information for each stack
                Console.WriteLine("\n------------------------------------------------");
                Console.WriteLine($"\nStack: {stack.StackName}");
                Console.WriteLine($"  Status: {stack.StackStatus.Value}");
                Console.WriteLine($"  Created: {stack.CreationTime}");

                // The tags of each stack (etc.)
                if (stack.Tags.Count > 0)
                {
                    Console.WriteLine("  Tags:");
                    foreach (Tag tag in stack.Tags)
                        Console.WriteLine($"    {tag.Key}, {tag.Value}");
                }

                // The resources of each stack
                DescribeStackResourcesResponse responseDescribeResources =
                  await cfnClient.DescribeStackResourcesAsync(new DescribeStackResourcesRequest
                  {
                      StackName = stack.StackName
                  });
                if (responseDescribeResources.StackResources.Count > 0)
                {
                    Console.WriteLine("  Resources:");
                    foreach (StackResource resource in responseDescribeResources.StackResources)
                        Console.WriteLine($"    {resource.LogicalResourceId}: {resource.ResourceStatus}");
                }
            }
            Console.WriteLine("\n------------------------------------------------");
        }
    }
}

References: AWS official Documentation


Print Share Comment Cite Upload Translate
APA
Ahmed Adel | Sciencx (2024-03-28T11:01:42+00:00) » AWSSDK.CloudFormation (for AWS CloudFormation). Retrieved from https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/.
MLA
" » AWSSDK.CloudFormation (for AWS CloudFormation)." Ahmed Adel | Sciencx - Saturday September 11, 2021, https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/
HARVARD
Ahmed Adel | Sciencx Saturday September 11, 2021 » AWSSDK.CloudFormation (for AWS CloudFormation)., viewed 2024-03-28T11:01:42+00:00,<https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/>
VANCOUVER
Ahmed Adel | Sciencx - » AWSSDK.CloudFormation (for AWS CloudFormation). [Internet]. [Accessed 2024-03-28T11:01:42+00:00]. Available from: https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/
CHICAGO
" » AWSSDK.CloudFormation (for AWS CloudFormation)." Ahmed Adel | Sciencx - Accessed 2024-03-28T11:01:42+00:00. https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/
IEEE
" » AWSSDK.CloudFormation (for AWS CloudFormation)." Ahmed Adel | Sciencx [Online]. Available: https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/. [Accessed: 2024-03-28T11:01:42+00:00]
rf:citation
» AWSSDK.CloudFormation (for AWS CloudFormation) | Ahmed Adel | Sciencx | https://www.scien.cx/2021/09/11/awssdk-cloudformation-for-aws-cloudformation/ | 2024-03-28T11:01:42+00:00
https://github.com/addpipe/simple-recorderjs-demo