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

ec2_placement_group.tf#L3
resource "aws_placement_group" "managers" {
  name      = "managers"
  strategy  = "cluster"
}

resource "aws_placement_group" "workers" {
18_auto_group.tf#L1
resource "aws_placement_group" "auto-pl-group" {
  name     = "auto-pl-group"
  strategy = "cluster"
}

resource "aws_autoscaling_group" "auto-auto-group" {
18_regroup.tf#L1
resource "aws_placement_group" "ehpark_place" {
    name = "ehpark-place"
    strategy = "cluster"

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

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).

risk-label

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.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

slurm_headnode_cloudformation.yml#L370
    Type: AWS::EC2::PlacementGroup
    Properties:
      Strategy: cluster

  SlurmManagementEC2:
    DependsOn: PublicSubnet1
pilosassb.yml#L246
    Type: AWS::EC2::PlacementGroup
  PilosaInstanceProfile:
    Properties:
      Roles:
        - !Ref 'PilosaRole'
    Type: AWS::IAM::InstanceProfile
pilosa.yml#L243
    Type: AWS::EC2::PlacementGroup
  PilosaInstanceProfile:
    Properties:
      Roles:
        - !Ref 'PilosaRole'
    Type: AWS::IAM::InstanceProfile
ec2.yml#L21
    Type:                   AWS::EC2::PlacementGroup
    Properties:
       Strategy:            cluster
  PartitionPlacementGroup:
    Type:                   AWS::EC2::PlacementGroup
    Properties:
servers.yml#L114
    Type: AWS::EC2::PlacementGroup
    Properties:
      Strategy: spread
  WebAppGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
Ec2PlacementGroupSpecification.json#L4
    "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",
Ec2PlacementGroupSpecification.json#L3
    "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",
Ec2PlacementGroupSpecification.json#L3
    "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",
EC2PlacementGroupSpecification.json#L3
    "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",
Ec2PlacementGroupSpecification.json#L3
    "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

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. A spread placement group places instances on distinct hardware. A partition 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.