Skip to content

Latest commit

 

History

History

AutoScaling

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Auto Scaling code examples for the SDK for .NET

Overview

Shows how to use the AWS SDK for .NET to work with Amazon EC2 Auto Scaling.

Auto Scaling automatically scales EC2 instances, either with scaling policies or with scheduled scaling.

⚠ Important

  • Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Code examples

Prerequisites

For prerequisites, see the README in the dotnetv3 folder.

Get started

Single actions

Code excerpts that show you how to call individual service functions.

Scenarios

Code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Run the examples

Instructions

For general instructions to run the examples, see the README in the dotnetv3 folder.

Some projects might include a settings.json file. Before compiling the project, you can change these values to match your own account and resources. Alternatively, add a settings.local.json file with your local settings, which will be loaded automatically when the application runs.

After the example compiles, you can run it from the command line. To do so, navigate to the folder that contains the .csproj file and run the following command:

dotnet run

Alternatively, you can run the example from within your IDE.

Hello Auto Scaling

This example shows you how to get started using Auto Scaling.

Build and manage a resilient service

This example shows you how to create a load-balanced web service that returns book, movie, and song recommendations. The example shows how the service responds to failures, and how to restructure the service for more resilience when failures occur.

  • Use an Amazon EC2 Auto Scaling group to create Amazon Elastic Compute Cloud (Amazon EC2) instances based on a launch template and to keep the number of instances in a specified range.
  • Handle and distribute HTTP requests with Elastic Load Balancing.
  • Monitor the health of instances in an Auto Scaling group and forward requests only to healthy instances.
  • Run a Python web server on each EC2 instance to handle HTTP requests. The web server responds with recommendations and health checks.
  • Simulate a recommendation service with an Amazon DynamoDB table.
  • Control web server response to requests and health checks by updating AWS Systems Manager parameters.

Manage groups and instances

This example shows you how to do the following:

  • Create an Amazon EC2 Auto Scaling group with a launch template and Availability Zones, and get information about running instances.
  • Enable Amazon CloudWatch metrics collection.
  • Update the group's desired capacity and wait for an instance to start.
  • Terminate an instance in the group.
  • List scaling activities that occur in response to user requests and capacity changes.
  • Get statistics for CloudWatch metrics, then clean up resources.
Configuration settings

This example uses several configuration settings that are stored in settings.json to change the existing values.

Note: The image ID, instance type, and Availability Zone must be available in the same AWS Region as the account that's used to run the scenario. For information about how to get valid settings, see Find a Linux AMI.

  • GroupName - The name to use for the Auto Scaling group.
  • ImageId - The image ID to use with the Amazon EC2 Auto Scaling template. The AMI-ID column of the Amazon EC2 image locator table.
  • InstanceType - The instance type to use with the template. The Instance Type column of the Amazon EC2 image locator table.
  • LaunchTemplateName - The name of the launch template.
  • AvailabilityZone - The Availability Zone for the launch template. The Zone column of the Amazon EC2 image locator table.
  • ServiceLinkedRoleArn - The Amazon Resource Name (ARN) of a serivce-linked role that will be used to create the Auto Scaling group.

Tests

⚠ Running tests might result in charges to your AWS account.

To find instructions for running these tests, see the README in the dotnetv3 folder.

Additional resources


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0