Amazon AWS SDK Betriebsanweisung Seite 57

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 73
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 56
5 CreateSecurityGroupRequest securityGroupRequest = new CreateSecurity
GroupRequest();
securityGroupRequest.GroupName = "GettingStartedGroup";
securityGroupRequest.GroupDescription = "Getting Started Security Group";
ec2.CreateSecurityGroup(securityGroupRequest);
10 }
catch (AmazonEC2Exception ae)
{
if (string.Equals(ae.ErrorCode, "InvalidGroup.Duplicate", StringCompar
ison.InvariantCulture))
{
15 Console.WriteLine(ae.Message);
}
else
{
throw;
20 }
}
To enable access to the group, we create an ipPermission object with the IP address set to the CIDR
representation of the IP address of the local computer. The "/32" suffix on the IP address indicates that
the security group should accept traffic only from the local computer.We also configure the ipPermission
object with the TCP protocol and port 3389 (RDP).You will need to fill in the IP address of the local
computer. If your connection to the Internet is mediated by a firewall or some other type of proxy, you will
need to determine the external IP address that the proxy uses. One technique is to query a search engine
such as Google or Bing with the string: "what is my IP address".
1
// TODO - Change the code below to use your external IP address.
String ipSource = "XXX.XXX.XXX.XX/32";
5 List<String> ipRanges = new List<String>();
ipRanges.Add(ipSource);
List<IpPermissionSpecification> ipPermissions = new List<IpPermissionSpe
cification>();
IpPermissionSpecification ipPermission = new IpPermissionSpecification();
10 ipPermission.IpProtocol = "tcp";
ipPermission.FromPort = 3389;
ipPermission.ToPort = 3389;
ipPermission.IpRanges = ipRanges;
ipPermissions.Add(ipPermission);
The final step is to call ec2.authorizeSecurityGroupIngress with the name of our security group
and the ipPermission object.
1 try {
// Authorize the ports to be used.
AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSe
curityGroupIngressRequest();
ingressRequest.IpPermissions = ipPermissions;
5 ingressRequest.GroupName = "GettingStartedGroup";
ec2.AuthorizeSecurityGroupIngress(ingressRequest);
} catch (AmazonEC2Exception ae) {
if (String.Equals(ae.ErrorCode, "InvalidPermission.Duplicate", String
Version v2.0.0
53
AWS SDK for .NET Developer Guide
Step 2: Setting Up a Security Group
Seitenansicht 56
1 2 ... 52 53 54 55 56 57 58 59 60 61 62 ... 72 73

Kommentare zu diesen Handbüchern

Keine Kommentare