简体   繁体   English

AWS CloudFormation .NET SDK

[英]AWS CloudFormation .NET SDK

I'm trying to do some specific manipulations with CloudFormation with ASP.NET. 我正在尝试对带有ASP.NET的CloudFormation进行一些特定的操作。 In my learning journey, I'm simply trying to display my CloudFormation stacks in a web display. 在学习过程中,我只是试图在Web显示器中显示CloudFormation堆栈。 Disclaimer -- I'm not a specialized developer and am working my way towards relearning and updating my knowledge from years ago. 免责声明-我不是专业开发人员,并且正在努力重新学习和更新几年前的知识。

I have been using the boilerplate AWS SDK template in ASP.NET and the preview version of AWS SDK that has CloudFormation capabilities in it and unfortunately, I'm having a hard time converting their examples from Console to Web. 我一直在使用ASP.NET中的样板AWS开发工具包模板和其中具有CloudFormation功能AWS开发工具包的预览版,不幸的是,我很难将其示例从Console转换为Web。 The website won't even write to the console when I monitor it in the inspect/developer mode. 当我在检查/开发人员模式下监视网站时,该网站甚至都不会写入控制台。 I cleaned up a bit of the code in these examples to clear out the ec2 and s3 clutter. 我在这些示例中清理了一些代码,以清除ec2和s3的混乱情况。

image example: ttps://pasteboard.co/GLhjCPt.png 图片示例:ttps://pasteboard.co/GLhjCPt.png

Default.aspx.cs: Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.IO;

using Amazon;
using Amazon.CloudFormation;
using Amazon.CloudFormation.Model;
using Amazon.CloudFormation.Resources;
using System.Linq;

namespace AwsWebApp2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected IAmazonCloudFormation acf;

        protected void Page_Load(object sender, EventArgs e)
        {

            sb = new StringBuilder(1024);
            using (StringWriter sr = new StringWriter(sb))
            {
                try
                {
                    acf = new AmazonCloudFormationClient();
                    this.WriteCloudFormationInfo();
                }
                catch (AmazonCloudFormationException ex)
                {
                    if (ex.ErrorCode != null && ex.ErrorCode.Equals("InvalidClientTokenId"))
                    {
                        sr.WriteLine("The account you are using is not signed up for Amazon CloudFormation.");
                        sr.WriteLine("<br />");
                        sr.WriteLine("<br />");
                    }
                    else
                    {
                        sr.WriteLine("Exception Message: " + ex.Message);
                        sr.WriteLine("<br />");
                        sr.WriteLine("Response Status Code: " + ex.StatusCode);
                        sr.WriteLine("<br />");
                        sr.WriteLine("Error Code: " + ex.ErrorCode);
                        sr.WriteLine("<br />");
                        sr.WriteLine("Error Type: " + ex.ErrorType);
                        sr.WriteLine("<br />");
                        sr.WriteLine("Request ID: " + ex.RequestId);
                        sr.WriteLine("<br />");
                        sr.WriteLine("<br />");
                    }
                    this.acfPlaceholder.Text = sr.ToString();
                }
            }

        }

        private void WriteCloudFormationInfo()
        {
            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);
                    }

                }

            }
        }

    }
}

Default.aspx: Default.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AwsWebApp2._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>My AWS Enabled Application - AwsWebApp2</title>
    <link rel="stylesheet" href="styles/styles.css" type="text/css" media="screen" charset="utf-8"/>
</head>
<html>
<body>
<div id="content" class="container">

    <div class="section grid grid5 gridlast ec2">
        <h2>Amazon CloudFormations:</h2>
        <ul>
            <asp:Label ID="acfPlaceholder" runat="server"></asp:Label>
        </ul>
    </div>

</div>
</body>
</html>

使用System.Diagnostics.Debug.Writeline()当您选择“显示来自(下拉)调试的输出”时,这将显示在Visual Studio的“输出”窗口中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM