Giter Club home page Giter Club logo

ec2-volume-manager's Introduction

AWS EC2 Volume manager

The ec2-volume-manager, manages the attachment of volumes to ec2 instances. When the instance is stopped or terminated, the volume attachments are removed. When a new instance is started, an volume is attached to it. The goal of the volume manager is to be able to update the AMI of a stateful server, without loosing the data by defining a autoscaling group of instance size 1 and perform a rolling update.

How does it work?

The manager will listen to all EC2 instance state change notifications. When an instance with the tag ec2-volume-manager-attachments reaches the state running, it will attach all volumes with the same tag and value. The volumes will need to have a tag device-name which is used in the volume attachment.

How do I use it?

You can start using the EC2 volume manager, in three simple steps:

  1. deploy the ec2-volume-manager
  2. create and tag the volumes
  3. create an auto scaling group size 1, propagating the tag

deploy the ec2-volume-manager

To deploy the provider, type:

git clone https://github.com/binxio/ec2-volume-manager.git
cd ec2-ec2-volume-manager
aws cloudformation deploy \
        --capabilities CAPABILITY_IAM \
        --stack-name ec2-volume-manager \
        --template ./cloudformation/ec2-volume-manager.yaml

Create one or more volumes to attach

Create the volumes to attach and tag them with an ec2-volume-manager-attachment value:

  Disk1:
    Type: AWS::EC2::Volume
    Properties:
      AvailabilityZone: !Sub '${AWS::Region}a'
      Size: 8
      Tags:
        - Key: ec2-volume-manager-attachment'
          Value: stateful-instance-1
        - Key: device-name
          Value: xvdf

  Disk2:
    Type: AWS::EC2::Volume
    Properties:
      AvailabilityZone: !Sub '${AWS::Region}b'
      Size: 8
      Tags:
        - Key: ec2-volume-manager-attachment
          Value: stateful-instance-1
        - Key: device-name
          Value: xvdg

Create an auto scaling group

Create an auto scaling group and apply the tag ec2-volume-manager-attachment to the instances:

  AutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      MinSize: '0'
      MaxSize: '1'
      DesiredCapacity: '1'
      Tags:
        - Key: ec2-volume-manager-attachment
          Value: stateful-instance-1
          PropagateAtLaunch: true
    UpdatePolicy:
      AutoScalingRollingUpdate:
        MinInstancesInService: 0
        MaxBatchSize: 1
        WaitOnResourceSignals: true

That is all. If you want to see it all in action, deploy the demo.

Note that the instance should wait in the boot script, until all volumes have been attached before proceeding with the boot sequence and report succesful completion using cfn-signal.

Deploy the demo

In order to deploy the demo, type:

export VPC_ID=$(aws ec2  --output text --query 'Vpcs[?IsDefault].VpcId' describe-vpcs)
export SUBNET_IDS=$(aws ec2 describe-subnets --output text \
                --filters Name=vpc-id,Values=$(VPC_ID) \
				          Name=default-for-az,Values=true \
                --query 'join(`,`,sort_by(Subnets[?MapPublicIpOnLaunch], &AvailabilityZone)[*].SubnetId)')
aws cloudformation deploy \
        --capabilities CAPABILITY_NAMED_IAM \
        --stack-name ec2-volume-manager-demo \
        --template ./cloudformation/demo-stack.yaml \
        --parameter-overrides VPC=$VPC_ID Subnets=$SUBNET_IDS

Read the blog too: How to update an ec2 instance with volume attachments using CloudFormation

ec2-volume-manager's People

Contributors

arjanvanbekkum avatar mvanholsteijn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

ec2-volume-manager's Issues

KeyError: 'Tags'

we have the ec2 volume manager up and running in one of our aws accounts.

even it seems to work fine we have from time to time the following error in the logs and i am not sure about any possible impacts

[ERROR] KeyError: 'Tags'
Traceback (most recent call last):
  File "/var/task/ec2_volume_manager/manager.py", line 211, in handler
    if not instance.attachment_name:
  File "/var/task/ec2_volume_manager/ec2_instance.py", line 25, in attachment_name
    return self.tags.get("ec2-volume-manager-attachment", None)
  File "/var/task/ec2_volume_manager/ec2_instance.py", line 33, in tags
    return {t["Key"]: t["Value"] for t in self["Tags"]}

please advise how to fix this error.

Access denied to S3

Launching the command:

git clone https://github.com/binxio/ec2-volume-manager.git
cd ec2-volume-manager
aws cloudformation --profile terraform-aria deploy \
        --capabilities CAPABILITY_IAM \
        --stack-name ec2-volume-manager \
        --template ./cloudformation/ec2-volume-manager.yaml

i'm receiving this error on CloudFormation events console:

Resource handler returned message: "Your access has been denied by S3, please make sure your request credentials have permission to GetObject for binxio-public-eu-south-1/lambdas/ec2-volume-manager-0.1.2.zip. S3 Error Code: AccessDenied. S3 Error Message: Access Denied (Service: Lambda, Status Code: 403, Request ID: e0f28f40-fa25-40b2-a83d-79bbcc818766)" (RequestToken: 013c4461-207f-d734-6cc7-c72206eca600, HandlerErrorCode: AccessDenied)

CFNCustomProviderZipFileName Outdated

The lambda code file reference in the cloudformation yaml is outdated. In the last update to v0.1.3 the file name was not updated to reflect this.

The issue can be resolved by:

Parameters:
LambdaS3Bucket: { Type: String, Default: '' }
CFNCustomProviderZipFileName: { Type: String, Default: lambdas/ec2-volume-manager-0.1.3.zip}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.