aws(学习笔记第三十四课) dockerized-app with asg-alb

aws(学习笔记第三十四课) dockerized-app with asg-alb

  • 使用cdk生成dockerized-app并使用AutoScalingGroupApplicationLoaderBalancer

学习内容:

  • 使用cdk生成dockerized-app并使用AutoScalingGroupApplicationLoaderBalancer
  • AutoScalingGroup中使用efs以及RDS

1. 整体架构

1.1 代码链接

代码链接(docker-app-with-asg-alb)

1.2 代码手动修改部分

这里的代码没有完全实现是理想的部署就能运行,需要修改几个地方。

1.2.1 rds_stack.py

修改instance_type=ec2.InstanceType.of这里的参数。不修改的话创建数据库运行失败。在这里插入图片描述
修改后的代码:

from aws_cdk import (
    aws_rds as rds,
    aws_ec2 as ec2,
    RemovalPolicy, Stack
    )
from constructs import Construct


class RDSStack(Stack):

    def __init__(self, scope: Construct, id: str, props, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Creates a security group for AWS RDS
        sg_rds = ec2.SecurityGroup(
                self,
                id="sg_rds",
                vpc=props['vpc'],
                security_group_name="sg_rds"
        )

        # Adds an ingress rule which allows resources in the VPC's CIDR
        # to access the database.
        sg_rds.add_ingress_rule(
            peer=ec2.Peer.ipv4("10.0.0.0/16"),
            connection=ec2.Port.tcp(3306)
        )

        # Master username is 'admin' and database password is automatically
        # generated and stored in AWS Secrets Manager
        my_sql = rds.DatabaseInstance(
                self, "RDS",
                engine=rds.DatabaseInstanceEngine.mysql(
                    version=rds.MysqlEngineVersion.VER_8_0_39
                ),
                vpc=props['vpc'],
                port=3306,
                instance_type=ec2.InstanceType.of(
                    ec2.InstanceClass.R7G,
                    ec2.InstanceSize.LARGE,
                    ),
                removal_policy=RemovalPolicy.DESTROY,
                security_groups=[sg_rds]
                )
1.2.2 efs_stack.py

修改了efs创建和security group的创建顺序
在这里插入图片描述
修改后的代码:

from aws_cdk import (
    aws_efs as efs,
    aws_ec2 as ec2,
    Stack
    )
from constructs import Construct

class StorageStack(Stack):

    def __init__(self, scope: Construct, id: str, props, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        sg_efs = ec2.SecurityGroup(
                self,
                id="sg_efs",
                vpc=props['vpc'],
                security_group_name="sg_efs"
                )

        sg_efs.add_ingress_rule(
                peer=ec2.Peer.ipv4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值