AWS Amazon EC2 Placement Group
This page shows how to write Terraform and CloudFormation for Amazon EC2 Placement Group and write them securely.
aws_placement_group (Terraform)
The Placement Group in Amazon EC2 can be configured in Terraform with the resource name aws_placement_group
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_placement_group" "managers" {
name = "managers"
strategy = "cluster"
}
resource "aws_placement_group" "workers" {
resource "aws_placement_group" "auto-pl-group" {
name = "auto-pl-group"
strategy = "cluster"
}
resource "aws_autoscaling_group" "auto-auto-group" {
resource "aws_placement_group" "ehpark_place" {
name = "ehpark-place"
strategy = "cluster"
Parameters
-
arn
optional computed - string -
id
optional computed - string -
name
required - string -
placement_group_id
optional computed - string -
strategy
required - string -
tags
optional - map from string to string
Explanation in Terraform Registry
Provides an EC2 placement group. Read more about placement groups in AWS Docs.
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::PlacementGroup (CloudFormation)
The PlacementGroup in EC2 can be configured in CloudFormation with the resource name AWS::EC2::PlacementGroup
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::EC2::PlacementGroup
Properties:
Strategy: cluster
SlurmManagementEC2:
DependsOn: PublicSubnet1
Type: AWS::EC2::PlacementGroup
PilosaInstanceProfile:
Properties:
Roles:
- !Ref 'PilosaRole'
Type: AWS::IAM::InstanceProfile
Type: AWS::EC2::PlacementGroup
PilosaInstanceProfile:
Properties:
Roles:
- !Ref 'PilosaRole'
Type: AWS::IAM::InstanceProfile
Type: AWS::EC2::PlacementGroup
Properties:
Strategy: cluster
PartitionPlacementGroup:
Type: AWS::EC2::PlacementGroup
Properties:
Type: AWS::EC2::PlacementGroup
Properties:
Strategy: spread
WebAppGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
"AWS::EC2::PlacementGroup": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html",
"Properties": {
"Strategy": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html#cfn-ec2-placementgroup-strategy",
"PrimitiveType": "String",
"AWS::EC2::PlacementGroup": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html",
"Properties": {
"Strategy": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html#cfn-ec2-placementgroup-strategy",
"PrimitiveType": "String",
"AWS::EC2::PlacementGroup": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html",
"Properties": {
"Strategy": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html#cfn-ec2-placementgroup-strategy",
"PrimitiveType": "String",
"AWS::EC2::PlacementGroup": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html",
"Properties": {
"Strategy": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html#cfn-ec2-placementgroup-strategy",
"PrimitiveType": "String",
"AWS::EC2::PlacementGroup": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html",
"Properties": {
"Strategy": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-placementgroup.html#cfn-ec2-placementgroup-strategy",
"PrimitiveType": "String",
Parameters
-
Strategy
optional - String
Explanation in CloudFormation Registry
Specifies a placement group in which to launch instances. The strategy of the placement group determines how the instances are organized within the group. A
cluster
placement group is a logical grouping of instances within a single Availability Zone that benefit from low network latency, high network throughput. Aspread
placement group places instances on distinct hardware. Apartition
placement group places groups of instances in different partitions, where instances in one partition do not share the same hardware with instances in another partition.For more information, see Placement Groups in the Amazon EC2 User Guide.
Frequently asked questions
What is AWS Amazon EC2 Placement Group?
AWS Amazon EC2 Placement Group is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Placement Group?
For Terraform, the eggmuffin95/Container_Orchestration, k7nsuy/terraform and qpqpqp1224/terratest source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the aws-samples/aws-plugin-for-slurm, pilosa/infrastructure and pilosa/infrastructure source code examples are useful. See the CloudFormation Example section for further details.