2023-05-19 13:23:56 -06:00
# Amazon EC2 code examples for the SDK for Ruby
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
## Overview
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
Shows how to use the AWS SDK for Ruby to work with Amazon Elastic Compute Cloud (Amazon EC2).
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
<!--custom.overview.start-->
<!--custom.overview.end-->
2022-10-21 10:23:10 -06:00
2024-01-04 13:25:48 -05:00
_ Amazon EC2 is a web service that provides resizable computing capacity—literally, servers in Amazon's data centers—that you use to build and host your software systems. _
2021-10-13 19:30:48 +01:00
2023-05-19 13:23:56 -06:00
## ⚠ Important
2020-11-12 14:18:16 -08:00
2024-01-04 13:25:48 -05:00
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing ](https://aws.amazon.com/pricing/ ) and [Free Tier ](https://aws.amazon.com/free/ ).
2023-05-19 13:23:56 -06:00
* 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 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
<!--custom.important.start-->
<!--custom.important.end-->
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
## Code examples
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
### Prerequisites
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
For prerequisites, see the [README ](../../README.md#Prerequisites ) in the `ruby` folder.
2020-11-12 14:18:16 -08:00
2023-05-23 07:12:16 -06:00
2023-08-25 14:49:04 -04:00
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
2023-05-23 07:12:16 -06:00
2024-07-09 11:47:20 -04:00
### Get started
- [Hello Amazon EC2 ](hello/hello_ec2.rb#L4 ) (`DescribeSecurityGroups` )
2023-08-25 14:49:04 -04:00
### Single actions
2023-05-23 07:12:16 -06:00
2023-08-25 14:49:04 -04:00
Code excerpts that show you how to call individual service functions.
2020-11-12 14:18:16 -08:00
2024-09-25 15:25:54 -04:00
- [AllocateAddress ](ec2-ruby-example-elastic-ips.rb#L46 )
- [AssociateAddress ](ec2-ruby-example-elastic-ips.rb#L62 )
2024-04-30 12:22:08 -07:00
- [CreateKeyPair ](ec2-ruby-example-key-pairs.rb#L10 )
- [CreateRouteTable ](ec2-ruby-example-create-route-table.rb#L9 )
- [CreateSecurityGroup ](ec2-ruby-example-security-group.rb#L10 )
- [CreateSubnet ](ec2-ruby-example-create-subnet.rb#L10 )
- [CreateVpc ](ec2-ruby-example-create-vpc.rb#L8 )
- [DescribeInstances ](ec2-ruby-example-get-all-instance-info.rb#L9 )
- [DescribeRegions ](ec2-ruby-example-regions-availability-zones.rb#L9 )
- [ReleaseAddress ](ec2-ruby-example-elastic-ips.rb#L136 )
- [StartInstances ](ec2-ruby-example-start-instance-i-123abc.rb#L9 )
- [StopInstances ](ec2-ruby-example-stop-instance-i-123abc.rb#L8 )
- [TerminateInstances ](ec2-ruby-example-terminate-instance-i-123abc.rb#L12 )
2024-01-04 13:25:48 -05:00
<!--custom.examples.start-->
<!--custom.examples.end-->
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
## Run the examples
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
### Instructions
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
<!--custom.instructions.start-->
The quickest way to interact with this example code is to invoke a [Scenario ](#Scenarios ) from your command line. For example, `ruby some_scenario.rb` will invoke `some_scenario.rb` .
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
<!--custom.instructions.end-->
2020-11-12 14:18:16 -08:00
2024-07-09 11:47:20 -04:00
#### Hello Amazon EC2
This example shows you how to get started using Amazon EC2.
```
ruby hello/hello_ec2.rb
```
2020-11-12 14:18:16 -08:00
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
### Tests
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
⚠ Running tests might result in charges to your AWS account.
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
To find instructions for running these tests, see the [README ](../../README.md#Tests )
in the `ruby` folder.
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
<!--custom.tests.start-->
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
## Contribute
Code examples thrive on community contribution.
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
To learn more about the contributing process, see [CONTRIBUTING.md ](../../../CONTRIBUTING.md ).
<!--custom.tests.end-->
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
## Additional resources
2020-11-12 14:18:16 -08:00
2024-01-04 13:25:48 -05:00
- [Amazon EC2 User Guide ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html )
- [Amazon EC2 API Reference ](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Welcome.html )
- [SDK for Ruby Amazon EC2 reference ](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Ec2.html )
2023-05-19 13:23:56 -06:00
<!--custom.resources.start-->
<!--custom.resources.end-->
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
---
2020-11-12 14:18:16 -08:00
2023-05-19 13:23:56 -06:00
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2020-11-12 14:18:16 -08:00
2023-08-25 14:49:04 -04:00
SPDX-License-Identifier: Apache-2.0