Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Multi AZ Failover #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# mu-elasticache

Mu-elasticache is an extension [for the devops tool mu](https://github.com/stelligent/mu)

This extension automatically creates an elasticache redis cluster in all of
your specified environments

## Using this Extension

copy these files into your project repo, I like to place these extensions under
the folder "mu", so you would create a new directory called mu/elasticache
to hold these files

then place the following at the bottom of your mu.yml file
```yaml
extensions:
- url: mu/elasticache
```

This is all you need to do to get started.

The following environmental variables can be passed to your application
via mu.yml

```yaml
environment:
REDIS_HOST: ${ElasticacheCluster.PrimaryEndPoint.Address}
REDIS_PORT: ${ElasticacheCluster.PrimaryEndPoint.Port}
```

The following parameters are configurable:
* NumCacheNodes (default is 2 for Multi AZ failover)
* CacheNodeType (default is cache.t2.micro)
* AutomaticFailoverEnabled (default is true)

Example:

```yaml
parameters:
mu-service-SERVICE-acceptance:
NumCacheNodes: 1
AutomaticFailoverEnabled: false

mu-service-SERVICE-production:
NumCacheNodes: 2
AutomaticFailoverEnabled: true
```
69 changes: 37 additions & 32 deletions common-iam.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
Resources:
CloudFormationRole:
ElastiCachePolicy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Policies:
- PolicyName: deploy-elasticache
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- elasticache:AddTagsToResource
- elasticache:AuthorizeCacheSecurityGroupIngress
- elasticache:CreateCacheCluster
- elasticache:CreateCacheSubnetGroup
- elasticache:DeleteCacheCluster
- elasticache:DeleteCacheSubnetGroup
- elasticache:DescribeCacheClusters
- elasticache:DescribeCacheSecurityGroups
- elasticache:DescribeCacheSubnetGroups
- elasticache:DescribeEvents
- elasticache:ListTagsForResource
- elasticache:ModifyCacheCluster
- elasticache:ModifyCacheSubnetGroup
- elasticache:RemoveTagsFromResource
- elasticache:RevokeCacheSecurityGroupIngress
Resource: '*'
Effect: Allow
- Action:
- iam:CreateServiceLinkedRole
- iam:PutRolePolicy
Resource: 'arn:aws:iam::*:role/aws-service-role/elasticache.amazonaws.com/AWSServiceRoleForElastiCache*'
Condition:
StringLike:
iam:AWSServiceName: elasticache.amazonaws.com
Effect: Allow
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- elasticache:AddTagsToResource
- elasticache:AuthorizeCacheSecurityGroupIngress
- elasticache:CreateCacheCluster
- elasticache:CreateCacheSubnetGroup
- elasticache:CreateReplicationGroup
- elasticache:DeleteCacheCluster
- elasticache:DeleteCacheSubnetGroup
- elasticache:DeleteReplicationGroup
- elasticache:DescribeCacheClusters
- elasticache:DescribeCacheSecurityGroups
- elasticache:DescribeCacheSubnetGroups
- elasticache:DescribeReplicationGroup
- elasticache:DescribeReplicationGroups
- elasticache:DescribeEvents
- elasticache:ListTagsForResource
- elasticache:ModifyCacheCluster
- elasticache:ModifyCacheSubnetGroup
- elasticache:RemoveTagsFromResource
- elasticache:RevokeCacheSecurityGroupIngress
Resource: '*'
Effect: Allow
- Action:
- iam:CreateServiceLinkedRole
- iam:PutRolePolicy
Resource: 'arn:aws:iam::*:role/aws-service-role/elasticache.amazonaws.com/AWSServiceRoleForElastiCache*'
Condition:
StringLike:
iam:AWSServiceName: elasticache.amazonaws.com
Effect: Allow
Roles:
- Ref: CloudFormationRole
36 changes: 31 additions & 5 deletions service-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Parameters:
NumCacheNodes:
Type: String
Description: Number of cache nodes
Default: 1
Default: 2
CacheNodeType:
Type: String
Description: The compute and memory capacity of the node(s) in the Redis Cluster
Default: "cache.m3.medium"
Default: "cache.t2.micro"
AllowedValues:
- cache.t2.micro
- cache.t2.small
Expand Down Expand Up @@ -43,6 +43,10 @@ Parameters:
- cache.r3.2xlarge
- cache.r3.4xlarge
- cache.r3.8xlarge
AutomaticFailoverEnabled:
Type: String
Description: Indicates whether Multi-AZ is enabled. When Multi-AZ is enabled, a read-only replica is automatically promoted to a read-write primary cluster if the existing primary cluster fails.
Default: "true"

Resources:
ElasticacheSubnetGroup:
Expand Down Expand Up @@ -72,15 +76,37 @@ Resources:
Ref: ServiceSecurityGroup

ElasticacheCluster:
Type: "AWS::ElastiCache::CacheCluster"
Type: "AWS::ElastiCache::ReplicationGroup"
Properties:
Engine: "redis"
CacheNodeType:
Ref: CacheNodeType
NumCacheNodes:
NumCacheClusters:
Ref: NumCacheNodes
CacheSubnetGroupName:
Ref: ElasticacheSubnetGroup
VpcSecurityGroupIds:
AutomaticFailoverEnabled:
Ref: AutomaticFailoverEnabled
ReplicationGroupDescription:
Fn::Sub: ${Namespace}-${ServiceName}-${EnvironmentName}-cache
SecurityGroupIds:
- Fn::ImportValue:
Ref: ServiceSecurityGroup

Outputs:
ElasticacheClusterEndpointAddress:
Description: "Elastic Cache Cluster Endpoint Address"
Value:
Fn::Sub:
${ElasticacheCluster.PrimaryEndPoint.Address}
Export:
Name:
Fn::Sub: ${AWS::StackName}-ElasticacheClusterEndpointAddress
ElasticacheClusterEndpointPort:
Description: "Elastic Cache Cluster Endpoint Port"
Value:
Fn::Sub:
${ElasticacheCluster.PrimaryEndPoint.Port}
Export:
Name:
Fn::Sub: ${AWS::StackName}-ElasticacheClusterEndpointPort