0

Ich versuche, einige spezifische Manipulationen mit CloudFormation mit ASP.NET zu tun. In meiner Lernreise versuche ich einfach, meine CloudFormation-Stapel in einem Web-Display anzuzeigen. Disclaimer - Ich bin kein spezialisierter Entwickler und arbeite gerade daran, mein Wissen von Jahren neu zu lernen und zu aktualisieren.AWS CloudFormation .NET SDK

Ich habe die Vorlage AWS SDK Vorlage in ASP.NET und die Vorschauversion von AWS SDK that has CloudFormation capabilities in es verwendet und leider habe ich eine harte Zeit, um ihre examples from Console in Web konvertieren. Die Webseite wird nicht einmal auf die Konsole schreiben, wenn ich sie im inspect/developer mode kontrolliere. Ich habe ein bisschen Code in diesen Beispielen aufgeräumt, um das ec2- und s3-Durcheinander zu beseitigen.

Bild Beispiel: TTPs: //pasteboard.co/GLhjCPt.png

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:

<%@ 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> 

Antwort

0

Verwendung System.Diagnostics .Debug.Writeline() Dies wird im Ausgabefenster in Visual Studio angezeigt, wenn Sie "Ausgabe von (Dropdown) debuggen"

auswählen
Verwandte Themen