Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 883c8fd

Browse files
committed
Merge branch '28-add-elasticache-redis' into 'develop'
added elasticache, updated env vars to include redis service host Closes #28 See merge request verbose-equals-true/django-postgres-vue-gitlab-ecs!72
2 parents 8189bfe + 39d5d21 commit 883c8fd

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

awscdk/awscdk/cdk_app_root.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def __init__(
7474
self, "RdsDBCluster", vpc=self.vpc.vpc, full_app_name=full_app_name
7575
)
7676

77-
# self.elasticache = ElastiCache(
78-
# self, "ElastiCacheRedis", vpc=self.vpc.vpc
79-
# )
77+
self.elasticache = ElastiCache(
78+
self, "ElastiCacheRedis", vpc=self.vpc.vpc
79+
)
8080

8181
# image used for all django containers
8282
# gunicorn, daphne, celery workers, celery beat
@@ -92,6 +92,7 @@ def __init__(
9292
postgres_host=self.rds.rds_cluster.get_att(
9393
"Endpoint.Address"
9494
).to_string(),
95+
redis_host=self.elasticache.elasticache.attr_redis_endpoint_address, # noqa
9596
)
9697

9798
self.backend = Backend(

awscdk/awscdk/elasticache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def __init__(
2323
ip_protocol="tcp",
2424
to_port=6379,
2525
from_port=6379,
26-
# TODO: replace this with ECS security group
27-
source_security_group_id="security-group-id",
26+
source_security_group_id=vpc.vpc_default_security_group,
2827
)
2928
],
3029
)
@@ -47,5 +46,5 @@ def __init__(
4746
vpc_security_group_ids=[
4847
self.elasticache_security_group.get_att("GroupId").to_string()
4948
],
50-
cache_subnet_group_name=self.elasticache_subnet_group.cache_subnet_group_name,
49+
cache_subnet_group_name=self.elasticache_subnet_group.cache_subnet_group_name, # noqa
5150
)

awscdk/awscdk/env_vars.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def __init__(
1010
id: str,
1111
bucket_name: str,
1212
postgres_host: str,
13+
redis_host: str,
1314
db_secret: secrets.ISecret,
1415
**kwargs,
1516
) -> None:
@@ -36,6 +37,7 @@ def __init__(
3637
"SECRET_KEY": os.environ.get(
3738
"SECRET_KEY", "mysecretkey123"
3839
), # self.django_secret_key.to_string(),
40+
"REDIS_SERVICE_HOST": redis_host,
3941
}
4042

4143
self.secret_variables = {

awscdk/stack.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ Resources:
665665
- - "{{resolve:secretsmanager:"
666666
- Ref: RdsDBClusterDBSecret28397CCA
667667
- :SecretString:password::}}
668-
Port: 5432
669668
Tags:
670669
- Key: StackName
671670
Value: dev-mysite-com
@@ -675,6 +674,49 @@ Resources:
675674
- GroupId
676675
Metadata:
677676
aws:cdk:path: dev-mysite-com-stack/RdsDBCluster/DBCluster
677+
ElastiCacheRedisElastiCacheSecurityGroupA36895A6:
678+
Type: AWS::EC2::SecurityGroup
679+
Properties:
680+
GroupDescription: ElastiCacheSecurityGroup
681+
SecurityGroupIngress:
682+
- FromPort: 6379
683+
IpProtocol: tcp
684+
SourceSecurityGroupId:
685+
Fn::GetAtt:
686+
- VpcC3027511
687+
- DefaultSecurityGroup
688+
ToPort: 6379
689+
Tags:
690+
- Key: StackName
691+
Value: dev-mysite-com
692+
VpcId:
693+
Ref: VpcC3027511
694+
Metadata:
695+
aws:cdk:path: dev-mysite-com-stack/ElastiCacheRedis/ElastiCacheSecurityGroup
696+
ElastiCacheRedisCfnSubnetGroup403949FE:
697+
Type: AWS::ElastiCache::SubnetGroup
698+
Properties:
699+
Description: The subnet group for ElastiCache
700+
SubnetIds:
701+
- Ref: VpcIsolatedSubnet1SubnetDC3C6AF8
702+
- Ref: VpcIsolatedSubnet2SubnetB479B99C
703+
Metadata:
704+
aws:cdk:path: dev-mysite-com-stack/ElastiCacheRedis/CfnSubnetGroup
705+
ElastiCacheRedisElastiCacheClusterRedis25390D9F:
706+
Type: AWS::ElastiCache::CacheCluster
707+
Properties:
708+
CacheNodeType: cache.t2.micro
709+
Engine: redis
710+
NumCacheNodes: 1
711+
Tags:
712+
- Key: StackName
713+
Value: dev-mysite-com
714+
VpcSecurityGroupIds:
715+
- Fn::GetAtt:
716+
- ElastiCacheRedisElastiCacheSecurityGroupA36895A6
717+
- GroupId
718+
Metadata:
719+
aws:cdk:path: dev-mysite-com-stack/ElastiCacheRedis/ElastiCacheClusterRedis
678720
VariablesDjangoSecretKeyE4FA41EE:
679721
Type: AWS::SecretsManager::Secret
680722
Properties:
@@ -766,6 +808,11 @@ Resources:
766808
- :SecretString:password::}}
767809
- Name: SECRET_KEY
768810
Value: mysecretkey123
811+
- Name: REDIS_SERVICE_HOST
812+
Value:
813+
Fn::GetAtt:
814+
- ElastiCacheRedisElastiCacheClusterRedis25390D9F
815+
- RedisEndpoint.Address
769816
Essential: true
770817
Image:
771818
Fn::Join:
@@ -967,6 +1014,11 @@ Resources:
9671014
- :SecretString:password::}}
9681015
- Name: SECRET_KEY
9691016
Value: mysecretkey123
1017+
- Name: REDIS_SERVICE_HOST
1018+
Value:
1019+
Fn::GetAtt:
1020+
- ElastiCacheRedisElastiCacheClusterRedis25390D9F
1021+
- RedisEndpoint.Address
9701022
Essential: true
9711023
Image:
9721024
Fn::Join:
@@ -1149,6 +1201,11 @@ Resources:
11491201
- :SecretString:password::}}
11501202
- Name: SECRET_KEY
11511203
Value: mysecretkey123
1204+
- Name: REDIS_SERVICE_HOST
1205+
Value:
1206+
Fn::GetAtt:
1207+
- ElastiCacheRedisElastiCacheClusterRedis25390D9F
1208+
- RedisEndpoint.Address
11521209
Essential: true
11531210
Image:
11541211
Fn::Join:
@@ -1330,6 +1387,11 @@ Resources:
13301387
- :SecretString:password::}}
13311388
- Name: SECRET_KEY
13321389
Value: mysecretkey123
1390+
- Name: REDIS_SERVICE_HOST
1391+
Value:
1392+
Fn::GetAtt:
1393+
- ElastiCacheRedisElastiCacheClusterRedis25390D9F
1394+
- RedisEndpoint.Address
13331395
Essential: true
13341396
Image:
13351397
Fn::Join:

0 commit comments

Comments
 (0)