@104corp/cfn-web-module 中文文档教程

发布于 4年前 浏览 20 项目主页 更新于 3年前

NPM version

cfn Web Template

从 CloudFormation 模板部署 AWS WEB 服务

Architecture

Install

Use git clone to copy template

git clone https://github.com/104corp/104isgd-devops-cfn-web.git

Or use npm install

安装 Node.js 和 npm 首先!

npm i @104corp/cfn-web-module

Usage

对于 Prod(没有计划的操作)

---
AWSTemplateFormatVersion: "2010-09-09"
Resources:
  Infra:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        AutoScalingDesiredMax: 4
        AutoScalingDesiredMin: 2
        AutoScalingOutPolicyHighCPU: 80
        AutoScalingOutPolicyLowCPU: 30
        ALBLogEnable: true
        ALBScheme: internal
        ALBListenerHttpsACMArn: arn:aws:acm:ap-northeast-1:685256291126:certificate/235ab25a-3bbc-43f1-8588-ad8a106fe4ae
        UserdataA: ""
        UserdataB: ""
        UserdataC: ""
        InstanceImageId: ""
        ALBLogLifecycleExpirationInDays: 30
        ProductName: aws-06-web
        VPCId: vpc-0651a7ee9874c4bbf
        VPCSubnetIdForELB: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        VPCSubnetIdForEC2: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
      TemplateURL: "./node_modules/@104corp/cfn-web-module/templates/web.yaml"

对于 Dev/Stg(有计划的操作)

---
AWSTemplateFormatVersion: "2010-09-09"
Resources:
  Infra:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        AutoScalingDesiredMax: 4
        AutoScalingDesiredMin: 2
        AutoScalingOutPolicyHighCPU: 80
        AutoScalingOutPolicyLowCPU: 30
        ALBLogEnable: true
        ALBScheme: internal
        ALBListenerHttpsACMArn: arn:aws:acm:ap-northeast-1:685256291126:certificate/235ab25a-3bbc-43f1-8588-ad8a106fe4ae
        UserdataA: ""
        UserdataB: ""
        UserdataC: ""
        InstanceImageId: ""
        ALBLogLifecycleExpirationInDays: 30
        ProductName: aws-06-web
        VPCId: vpc-0651a7ee9874c4bbf
        VPCSubnetIdForELB: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        VPCSubnetIdForEC2: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        PowerOnTime: '0 0 * * *'
        PowerOffTime: '0 11 * * *'
      TemplateURL: "./node_modules/@104corp/cfn-web-module/templates/web.yaml"

Package

$ aws cloudformation package --template-file example.yml --s3-bucket <你的 cfn 模板桶>; --output-template-file packaged.yml

Deploy

$ aws cloudformation deploy --template-file packaged.yml --stack-name

templates/web

Description

AWS 服务:

  • application loadbalancer
  • listen port 80 & 443
  • access log enable
  • autoscaling group
  • change capacity by cloudwatch cpu usage
  • iam role
  • ssm policy
  • s3 bucket
  • Application Loadbalancer log
  • security group
  • AutoScaling Group
  • Application LoadBalancer
  • cloudwatch
  • cpu alarm high and low

Parameters

AutoScalingOutPolicyHighCPU

类型:字符串
描述:需要多少百分比的 cpu 使用率来扩展实例,默认是 80%。

AutoScalingOutPolicyLowCPU

类型:字符串
说明:缩减实例需要多少百分比的 cpu 使用率,默认为 30%。

AutoScalingDesiredMin

类型:字符串
描述:自动缩放最小实例容量,默认为 2。

AutoScalingDesiredMax

类型:String
说明:自动缩放最大实例容量,默认为 4。

ALBLogEnable

类型:String
说明:启用或禁用 LoadBalancer 日志,默认为 true。

ALBScheme

类型:字符串
说明:选择ELB网络,默认是internal。

ALBListenerHttpsACMArn

类型:字符串
说明:输入您的 ACM ARN,类似于 arn:aws:acm:region:123456789012:certificate/00000000-0000-0000-0000-000000000000

UserdataA

类型:字符串
说明:如果需要,输入您的 shell 脚本,默认为 ""

UserdataB

类型:String
说明:如果需要,输入您的 shell 脚本,默认为 ""

UserdataC

类型:String
说明:如果需要,输入您的 shell 脚本,默认为 ""

InstanceImageId

类型:String
说明:输入 AMI ID。

ALBLogLifecycleExpirationInDays:

类型:字符串
说明:S3 Bucket 生命周期,默认为 30 天。

ProductName

类型:字符串
说明:输入您的产品名称。 EG NewWeb、Hunter 等……

VPCId

类型:AWS::EC2::VPC::Id
说明:选择现有 VPC ID

VPCSubnetIdForELB

类型:AWS::EC2::Subnet::Id 说明:输入存在两个子网 ID 取决于 VPC For ElasticLoadbalancer。

VPCSubnetIdForEC2

类型:AWS::EC2::Subnet::Id
说明:输入存在两个子网 ID 取决于 VPC For EC2。

InstanceType

类型:字符串
描述:选择ec2实例类型,默认为t3.nano

Use For Lab/Stg env if needed it(Option).

我们提供十个Scheduled Action Function供使用。

Schedule Name and Parameter Name List

{sequence}
- First
- Second
- Third
- Fourth
- Fifth
- Sixth
- Seventh
- Eighth
- Ninth
- Tenth
- asgScheduledAction{sequence}:
  - ScheduledActions{sequence}
  - ScheduledActions{sequence}MaxSize
  - ScheduledActions{sequence}MinSize

ScheduledActionsFirst

类型:String
说明:Conrd格式如“0 8 * * *”,默认为0 0 * * *。 时区为 UTC(台北时间 -8)

ScheduledActionsFirstMaxSize

类型:String
说明:实例最大大小的计划操作。

ScheduledActionsFirstMinSize

类型:字符串
说明:实例最小大小的计划操作。

Maintenance

维护者:

  • 104corp

NPM version

cfn Web Template

AWS WEB Service deployment from CloudFormation Template

Architecture

Install

Use git clone to copy template

git clone https://github.com/104corp/104isgd-devops-cfn-web.git

Or use npm install

Install Node.js and npm first!

npm i @104corp/cfn-web-module

Usage

For Prod(without scheduled action)

---
AWSTemplateFormatVersion: "2010-09-09"
Resources:
  Infra:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        AutoScalingDesiredMax: 4
        AutoScalingDesiredMin: 2
        AutoScalingOutPolicyHighCPU: 80
        AutoScalingOutPolicyLowCPU: 30
        ALBLogEnable: true
        ALBScheme: internal
        ALBListenerHttpsACMArn: arn:aws:acm:ap-northeast-1:685256291126:certificate/235ab25a-3bbc-43f1-8588-ad8a106fe4ae
        UserdataA: ""
        UserdataB: ""
        UserdataC: ""
        InstanceImageId: ""
        ALBLogLifecycleExpirationInDays: 30
        ProductName: aws-06-web
        VPCId: vpc-0651a7ee9874c4bbf
        VPCSubnetIdForELB: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        VPCSubnetIdForEC2: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
      TemplateURL: "./node_modules/@104corp/cfn-web-module/templates/web.yaml"

For Dev/Stg(with scheduled action)

---
AWSTemplateFormatVersion: "2010-09-09"
Resources:
  Infra:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        AutoScalingDesiredMax: 4
        AutoScalingDesiredMin: 2
        AutoScalingOutPolicyHighCPU: 80
        AutoScalingOutPolicyLowCPU: 30
        ALBLogEnable: true
        ALBScheme: internal
        ALBListenerHttpsACMArn: arn:aws:acm:ap-northeast-1:685256291126:certificate/235ab25a-3bbc-43f1-8588-ad8a106fe4ae
        UserdataA: ""
        UserdataB: ""
        UserdataC: ""
        InstanceImageId: ""
        ALBLogLifecycleExpirationInDays: 30
        ProductName: aws-06-web
        VPCId: vpc-0651a7ee9874c4bbf
        VPCSubnetIdForELB: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        VPCSubnetIdForEC2: subnet-044e3e0ca5d02d47c, subnet-0755b85dfb1b14fd2
        PowerOnTime: '0 0 * * *'
        PowerOffTime: '0 11 * * *'
      TemplateURL: "./node_modules/@104corp/cfn-web-module/templates/web.yaml"

Package

$ aws cloudformation package --template-file example.yml --s3-bucket <your cfn template bucket> --output-template-file packaged.yml

Deploy

$ aws cloudformation deploy --template-file packaged.yml --stack-name <your stack name>

templates/web

Description

AWS Service :

  • application loadbalancer
  • listen port 80 & 443
  • access log enable
  • autoscaling group
  • change capacity by cloudwatch cpu usage
  • iam role
  • ssm policy
  • s3 bucket
  • Application Loadbalancer log
  • security group
  • AutoScaling Group
  • Application LoadBalancer
  • cloudwatch
  • cpu alarm high and low

Parameters

AutoScalingOutPolicyHighCPU

Type: String
Description: How many percent cpu usage need to scaling up instance, default is 80 percent.

AutoScalingOutPolicyLowCPU

Type: String
Description: How many percent cpu usage need to scaling down instance, default is 30 percent.

AutoScalingDesiredMin

Type: String
Description: Autoscaling minimum instance capacity, default is 2.

AutoScalingDesiredMax

Type: String
Description: Autoscaling maximum instance capacity, default is 4.

ALBLogEnable

Type: String
Description: Enable or Disable LoadBalancer log, default is true.

ALBScheme

Type: String
Description: Choice ELB network, default is internal.

ALBListenerHttpsACMArn

Type: String
Description: Enter Your ACM ARN look like arn:aws:acm:region:123456789012:certificate/00000000-0000-0000-0000-000000000000

UserdataA

Type: String
Description: Enter Your shell script if needed, default is ""

UserdataB

Type: String
Description: Enter Your shell script if needed, default is ""

UserdataC

Type: String
Description: Enter Your shell script if needed, default is ""

InstanceImageId

Type: String
Description: Enter AMI ID.

ALBLogLifecycleExpirationInDays:

Type: String
Description: S3 Bucket Lifecycle, default is 30 days.

ProductName

Type: String
Description: Enter Your ProductName. E.G. NewWeb, Hunter etc…

VPCId

Type: AWS::EC2::VPC::Id
Description: Choice Exist VPC ID

VPCSubnetIdForELB

Type: AWS::EC2::Subnet::Id Description: Enter exist two subnet id depens on VPC For ElasticLoadbalancer.

VPCSubnetIdForEC2

Type: AWS::EC2::Subnet::Id
Description: Enter exist two subnet id depens on VPC For EC2.

InstanceType

Type: String
Description: Choice ec2 instance type, default is t3.nano

Use For Lab/Stg env if needed it(Option).

We provider ten Scheduled Action Function for usage.

Schedule Name and Parameter Name List

{sequence}
- First
- Second
- Third
- Fourth
- Fifth
- Sixth
- Seventh
- Eighth
- Ninth
- Tenth
- asgScheduledAction{sequence}:
  - ScheduledActions{sequence}
  - ScheduledActions{sequence}MaxSize
  - ScheduledActions{sequence}MinSize

ScheduledActionsFirst

Type: String
Description: Conrd format like "0 8 * * * ", default is 0 0 * * * . Time Zone is UTC(Teipei Time -8)

ScheduledActionsFirstMaxSize

Type: String
Description: scheduled action for instance max size.

ScheduledActionsFirstMinSize

Type: String
Description: scheduled action for instance min size.

Maintenance

Maintainers:

  • 104corp
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文