Summary

Hakuna can automatize the provisioning and the disposal of AWS CloudFormation stacks.

Flavour: awscf

Requirements

Requirement Description
CloudFormation stack is stored in S3 Hakuna Cloud can manage only stacks that are stored on S3.
Declared IP Some triggers requires an IP address to work. A CloudFormation resource can expose an IP address using an output named HakunaIp.

IP Address for ModProxy

The trigger ModProxy requires an IP address to redirect HTTPS requests. In the context of this flavour, the IP address of the resource to use as the proxy destination must be listed in the Outputs section of the stack:

Supported triggers

Trigger Supported Description
HTTP/HTTPS ModProxy Switch on the instance if an HTTP/S request is received
Metrics Switch off the instance if the CPU is low
Schedule Switch on or off the instance following a predefined schedule
SSH Enable SSH connection (eg: git)

Supported stop status

When the VHost is stopped, the CloudFormation stack and all its resources are deleted.

Stacks parameters are persisted in the VHost object, and are applied to any new stack created as a consequence of a trigger.

It is possible to change those parameters using the appropriate cli command: hakuna vhost update.

Configuration

Required IAM User

Hakuna Cloud requires an IAM user to call AWS API on user behalf, in order to start and stop EC2 instances. In order to correctly configure an aws/ec2 provider, please create an IAM user configured with:

  • Programmatic access enabled: create an access key ID and a secret access key and use these credentials in the Cloud Provider configuration
  • AWS Management Console access disabled
  • Add to the IAM User the following IAM Policy:
Version: '2012-10-17'
Statement:
- Sid: HakunaCloudPolicy
  Effect: Allow
  Action:
      - ec2:AuthorizeSecurityGroupIngress
      - ec2:DeregisterImage
      - ec2:DescribeInstances
      - ec2:DescribeAddresses
      - ec2:DeleteTags
      - ec2:DescribeInstanceAttribute
      - ec2:CreateKeyPair
      - ec2:CreateImage
      - ec2:DescribePlacementGroups
      - ec2:GetLaunchTemplateData
      - ec2:DescribeVolumeStatus
      - ec2:DescribeNetworkInterfaces
      - ec2:StartInstances
      - ec2:DescribeAvailabilityZones
      - ec2:CreateSecurityGroup
      - ec2:DescribeVolumes
      - ec2:DescribeKeyPairs
      - ec2:DescribeInstanceStatus
      - ec2:AuthorizeSecurityGroupEgress
      - ec2:TerminateInstances
      - ec2:DescribeLaunchTemplates
      - ec2:DescribeTags
      - ec2:CreateTags
      - ec2:RegisterImage
      - ec2:RunInstances
      - ec2:StopInstances
      - ec2:DescribeVolumeAttribute
      - ec2:DescribeInstanceCreditSpecifications
      - ec2:DescribeImages
      - ec2:DeleteSecurityGroup
      - ec2:DescribeSubnets
  Resource: "*"

Provider

The following table shows how is your AWS Account represented in Hakuna Cloud.

Key Value Description
Name String An arbitrary name to identify your account
Identity String AWS Access Key ID
Credential String AWS Secret Access Key

Provider Creation with the hakuna CLI

A Cloud Provider in the hakuna CLI is called simply provider. To create and configure a provider for AWS CloudFormation follow the instructions below:

  1. Open a terminal and run hakuna provider create

You will be asked to choose from all available providers, a.k.a. flavours.

  1. Choose awscf

  2. Choose an arbitrary name for the cloud provider, for example “AWS CF Work Account”

  3. Paste the Access Key ID of your AWS account

  4. Paste the Secret Access Key of your AWS account as well

  5. Type the AWS Region you want to host your CloudFormation stack to

Right after adding the credentials, the hakuna CLI will validate them and you will get a confirmation about the successfully created provider.

Add a VHost

After configuring the provider, in order to add a CloudFormation stack to Hakuna Cloud you need to create a VHost:

  1. Open a terminal and run hakuna vhost create
  2. Choose awscf from the list of available flavours
  3. Choose your previously created provider, say “AWS CF Work Account”
  4. The tool will show you a list of available CloudFormation stacks: choose the one you want to let Hakuna Cloud manage
  5. Specify a domain name for that stack