辅助魔法强化AWS上的服务扩大范围

辅助魔法

今日会把架构上的剩下服务讲完。
https://ithelp.ithome.com.tw/upload/images/20210925/20140172cAlcSy7dCm.png
NACL这边使用预设的,就不用在YAML特别撰写。

Route table的设定以下会用到

routeTableName:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref myVPC
      Tags:
        - Key: itdemo-rt-cf
          Value: v1
  routeName:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref routeTableName
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref igwName
  routeTableAssocName:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref subnetName
      RouteTableId: !Ref routeTableName

DestinationCidrBlock: 0.0.0.0/0,外网为最终目的地。

Internet gateway的设定以下会用到

igwName:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: itdemo-igw-cf
          Value: v1
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref myVPC 
      InternetGatewayId: !Ref igwName

整个YAML档如下:

Resources:
  myVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: itdemo-vpc-cf
          Value: v1
  subnetName:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: us-east-2a
      VpcId: !Ref myVPC
      CidrBlock: 10.0.0.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: itdemo-subnet-cf
          Value: v1
  igwName:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: itdemo-igw-cf
          Value: v1
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref myVPC 
      InternetGatewayId: !Ref igwName
  routeTableName:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref myVPC
      Tags:
        - Key: itdemo-rt-cf
          Value: v1
  routeName:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref routeTableName
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref igwName
  routeTableAssocName:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref subnetName
      RouteTableId: !Ref routeTableName
  secGroupName:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: itdemo-sg
      GroupDescription: it 30 days demo
      VpcId: !Ref myVPC 
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
      Tags:
        - Key: itdemo-sg-cf
          Value: v1
  myEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      BlockDeviceMappings:
        - DeviceName: "/dev/xvda"
          Ebs:
            VolumeSize: 30
            VolumeType: gp3
      KeyName: "itdemo"
      SubnetId: !Ref subnetName
      DisableApiTermination: false
      ImageId: ami-0443305dabd4be2bc
      InstanceType: "t3.micro"
      SecurityGroupIds:
        - !Ref secGroupName
      UserData: !Base64 |
        #!/bin/bash -ex
        # put your script here
      Tags:
        - Key: itdemo-ec2-cf
          Value: v1

CloudFormation建置环境步骤:

  1. Create Stack
  2. 选择你的YAML做上传,确定点选Next
    https://ithelp.ithome.com.tw/upload/images/20210925/2014017200UWfTWmRw.png
  3. Stack name随意取名
  4. 点选Next,到Create Stack
  5. 等待CloudFormation建立好资源
    https://ithelp.ithome.com.tw/upload/images/20210925/20140172k4dc3ILeps.png
    之前建立的好的SSH key就可以测试,机器能否远端连入,以下是成功远端连入
    https://ithelp.ithome.com.tw/upload/images/20210925/20140172yHzNbqOwZk.png
    删除资源,只要再回CloudFormation介面,点选delete,就可以把刚刚创建好的资源全部删除。
    https://ithelp.ithome.com.tw/upload/images/20210925/201401724azwnCgNBM.png
    若对云端不熟悉,建议从[Day6]开始看起,才会有对架构有全面的了解
    ps.至於Day6是哪一篇,可以从第一篇自己慢慢往上数,或是可以每一篇都看,或许会探索到新大陆

<<:  【Day 13】Array - Practice 1

>>:  [Day 12 - Bootstrap] Bootstrap一下,快速建立响应式网站

[Day21] 网格交易机器人行前准备

首先先更新登入的部分,之後会需要登入凭证,这边的一些变数可以再利用 然後是网格交易策略那边,一些参数...

Day 15 KYC + PYC=市场基本生存法则

因应各国个资保护法如雨後春笋般出现,在2C市场上不单单只有眼前的利益营收,更要有一套完善的隐私保护的...

[Day27]What is mapping?

hi!今天要介绍mapping!其实mapping很像一个hash table,有很多时候都会有一...

[神经机器翻译理论与实作] 你只需要专注力(II): 建立更专注的seq2seq模型

前言 注意力机制让预测目标单词之前比较其与所有来源单词(在翻译任务中精确地来说是词向量)之间的语意关...

Day24 ( 游戏设计 ) 记忆大考验

记忆大考验 教学原文参考:记忆大考验 这篇文章会使用「阵列」积木,建立两组灯号数据,搭配「函式」、「...