Parameters:
  ListenerPort:
    Type: Number
    Default: 8001
    Description: Port number for your website
  KeyName:
    Type: AWS::EC2::KeyPair::KeyName
    ConstraintDescription: Must be the name of an existing EC2 key pair
    Description: Select an existing EC2 key pair for SSH access
  CompanyName:
    Type: String
    Default: Example Company
    Description: Name of your Company
  CompanyDescription:
    Type: String
    Default: Example Description
    Description: Simple description of your company
  AboutUs:
    Type: String
    Default: Example About Us
    Description: About us
  CoreValues:
    Type: String
    Default: Example Core Values
    Description: Core Value of your company
  Service1Title:
    Type: String
    Default: Example Service 1
    Description: Title for your service 1
  Service1Description:
    Type: String
    Default: Example Description 1
    Description: Description for your service 1
  Service2Title:
    Type: String
    Default: Example Service 2
    Description: Title for your service 2
  Service2Description:
    Type: String
    Default: Example Description 2
    Description: Description for your service 2
  Service3Title:
    Type: String
    Default: Example Service 3
    Description: Title for your service 3
  Service3Description:
    Type: String
    Default: Example Description 3
    Description: Description for your service 3
  CompanyEmail:
    Type: String
    Default: contact@example.com
    Description: ""
  CompanyPhone:
    Type: String
    Default: 010-12345678
    Description: ""
  CompanyAddress:
    Type: String
    Default: Example Address
    Description: Address of your company
  SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64
Resources:
  DeploymentRoleC7BBCF2C:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: cloudformation.amazonaws.com
        Version: "2012-10-17"
      Description: Role for deploying this CloudFormation template
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonEC2FullAccess
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonVPCFullAccess
    Metadata:
      aws:cdk:path: EC2DeployStack/DeploymentRole/Resource
  DeploymentRoleDefaultPolicyB30A6D11:
    Type: AWS::IAM::Policy
    Properties:
      PolicyDocument:
        Statement:
          - Action:
              - iam:AddRoleToInstanceProfile
              - iam:AttachRolePolicy
              - iam:CreateInstanceProfile
              - iam:CreateRole
              - iam:DeleteInstanceProfile
              - iam:DeleteRole
              - iam:DeleteRolePolicy
              - iam:DetachRolePolicy
              - iam:GetInstanceProfile
              - iam:GetRole
              - iam:GetRolePolicy
              - iam:ListPolicies
              - iam:ListRoles
              - iam:PassRole
              - iam:PutRolePolicy
              - iam:RemoveRoleFromInstanceProfile
            Effect: Allow
            Resource:
              - arn:aws-cn:iam::aws:policy/AmazonSSMManagedInstanceCore
              - Fn::Join:
                  - ""
                  - - "arn:aws-cn:iam::"
                    - Ref: AWS::AccountId
                    - :instance-profile/ec2deploy-*
              - Fn::Join:
                  - ""
                  - - "arn:aws-cn:iam::"
                    - Ref: AWS::AccountId
                    - :policy/ec2deploy-*
              - Fn::Join:
                  - ""
                  - - "arn:aws-cn:iam::"
                    - Ref: AWS::AccountId
                    - :role/ec2deploy-*
          - Action:
              - lambda:AddPermission
              - lambda:CreateFunction
              - lambda:DeleteFunction
              - lambda:GetFunction
              - lambda:GetPolicy
              - lambda:InvokeFunction
              - lambda:RemovePermission
              - lambda:UpdateFunctionCode
              - lambda:UpdateFunctionConfiguration
            Effect: Allow
            Resource:
              Fn::Join:
                - ""
                - - "arn:aws-cn:lambda:"
                  - Ref: AWS::Region
                  - ":"
                  - Ref: AWS::AccountId
                  - :function:ec2deploy-*
          - Action:
              - cloudformation:DescribeStackEvents
              - cloudformation:DescribeStackResources
              - cloudformation:DescribeStacks
              - cloudformation:GetTemplate
              - s3:CreateBucket
              - s3:DeleteBucket
              - s3:DeleteBucketPolicy
              - s3:DeleteObject
              - s3:GetBucketPolicy
              - s3:GetObject
              - s3:ListBucket
              - s3:PutBucketPolicy
              - s3:PutObject
              - ssm:DeleteParameter
              - ssm:DescribeParameters
              - ssm:GetParameter
              - ssm:GetParameters
              - ssm:PutParameter
            Effect: Allow
            Resource: "*"
        Version: "2012-10-17"
      PolicyName: DeploymentRoleDefaultPolicyB30A6D11
      Roles:
        - Ref: DeploymentRoleC7BBCF2C
    Metadata:
      aws:cdk:path: EC2DeployStack/DeploymentRole/DefaultPolicy/Resource
  EC2deployVpcParamB91CBCEC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsHostnames: true
      EnableDnsSupport: true
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/Resource
  EC2deployVpcParamtemplatepublicSubnet1SubnetFCB7CF33:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone:
        Fn::Select:
          - 0
          - Fn::GetAZs: ""
      CidrBlock: 10.0.0.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: aws-cdk:subnet-name
          Value: template-public
        - Key: aws-cdk:subnet-type
          Value: Public
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/Subnet
  EC2deployVpcParamtemplatepublicSubnet1RouteTable1BC0AC83:
    Type: AWS::EC2::RouteTable
    Properties:
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/RouteTable
  EC2deployVpcParamtemplatepublicSubnet1RouteTableAssociation5F70C7CE:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1RouteTable1BC0AC83
      SubnetId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1SubnetFCB7CF33
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/RouteTableAssociation
  EC2deployVpcParamtemplatepublicSubnet1DefaultRoute56AFA579:
    Type: AWS::EC2::Route
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: EC2deployVpcParamIGW985AF470
      RouteTableId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1RouteTable1BC0AC83
    DependsOn:
      - EC2deployVpcParamVPCGW9A50FAD6
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/DefaultRoute
  EC2deployVpcParamtemplatepublicSubnet1EIP9FA810A0:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/EIP
  EC2deployVpcParamtemplatepublicSubnet1NATGateway39252FC7:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId:
        Fn::GetAtt:
          - EC2deployVpcParamtemplatepublicSubnet1EIP9FA810A0
          - AllocationId
      SubnetId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1SubnetFCB7CF33
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1
    DependsOn:
      - EC2deployVpcParamtemplatepublicSubnet1DefaultRoute56AFA579
      - EC2deployVpcParamtemplatepublicSubnet1RouteTableAssociation5F70C7CE
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet1/NATGateway
  EC2deployVpcParamtemplatepublicSubnet2Subnet4248AD3C:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone:
        Fn::Select:
          - 1
          - Fn::GetAZs: ""
      CidrBlock: 10.0.1.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: aws-cdk:subnet-name
          Value: template-public
        - Key: aws-cdk:subnet-type
          Value: Public
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/Subnet
  EC2deployVpcParamtemplatepublicSubnet2RouteTableDE9247CF:
    Type: AWS::EC2::RouteTable
    Properties:
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/RouteTable
  EC2deployVpcParamtemplatepublicSubnet2RouteTableAssociationE3E3C72D:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: EC2deployVpcParamtemplatepublicSubnet2RouteTableDE9247CF
      SubnetId:
        Ref: EC2deployVpcParamtemplatepublicSubnet2Subnet4248AD3C
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/RouteTableAssociation
  EC2deployVpcParamtemplatepublicSubnet2DefaultRouteEA3D3BA1:
    Type: AWS::EC2::Route
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: EC2deployVpcParamIGW985AF470
      RouteTableId:
        Ref: EC2deployVpcParamtemplatepublicSubnet2RouteTableDE9247CF
    DependsOn:
      - EC2deployVpcParamVPCGW9A50FAD6
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/DefaultRoute
  EC2deployVpcParamtemplatepublicSubnet2EIPCA0DEECC:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/EIP
  EC2deployVpcParamtemplatepublicSubnet2NATGateway5180F406:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId:
        Fn::GetAtt:
          - EC2deployVpcParamtemplatepublicSubnet2EIPCA0DEECC
          - AllocationId
      SubnetId:
        Ref: EC2deployVpcParamtemplatepublicSubnet2Subnet4248AD3C
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2
    DependsOn:
      - EC2deployVpcParamtemplatepublicSubnet2DefaultRouteEA3D3BA1
      - EC2deployVpcParamtemplatepublicSubnet2RouteTableAssociationE3E3C72D
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-publicSubnet2/NATGateway
  EC2deployVpcParamtemplateisolatedSubnet1Subnet19405962:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone:
        Fn::Select:
          - 0
          - Fn::GetAZs: ""
      CidrBlock: 10.0.2.0/24
      MapPublicIpOnLaunch: false
      Tags:
        - Key: aws-cdk:subnet-name
          Value: template-isolated
        - Key: aws-cdk:subnet-type
          Value: Private
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1/Subnet
  EC2deployVpcParamtemplateisolatedSubnet1RouteTableB7D553C3:
    Type: AWS::EC2::RouteTable
    Properties:
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1/RouteTable
  EC2deployVpcParamtemplateisolatedSubnet1RouteTableAssociation736894A1:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet1RouteTableB7D553C3
      SubnetId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet1Subnet19405962
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1/RouteTableAssociation
  EC2deployVpcParamtemplateisolatedSubnet1DefaultRoute35B1816F:
    Type: AWS::EC2::Route
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1NATGateway39252FC7
      RouteTableId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet1RouteTableB7D553C3
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet1/DefaultRoute
  EC2deployVpcParamtemplateisolatedSubnet2SubnetDDCB01CD:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone:
        Fn::Select:
          - 1
          - Fn::GetAZs: ""
      CidrBlock: 10.0.3.0/24
      MapPublicIpOnLaunch: false
      Tags:
        - Key: aws-cdk:subnet-name
          Value: template-isolated
        - Key: aws-cdk:subnet-type
          Value: Private
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2/Subnet
  EC2deployVpcParamtemplateisolatedSubnet2RouteTable0A212ECE:
    Type: AWS::EC2::RouteTable
    Properties:
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2/RouteTable
  EC2deployVpcParamtemplateisolatedSubnet2RouteTableAssociationAECAA678:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet2RouteTable0A212ECE
      SubnetId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet2SubnetDDCB01CD
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2/RouteTableAssociation
  EC2deployVpcParamtemplateisolatedSubnet2DefaultRoute2E0F73D2:
    Type: AWS::EC2::Route
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId:
        Ref: EC2deployVpcParamtemplatepublicSubnet2NATGateway5180F406
      RouteTableId:
        Ref: EC2deployVpcParamtemplateisolatedSubnet2RouteTable0A212ECE
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/template-isolatedSubnet2/DefaultRoute
  EC2deployVpcParamIGW985AF470:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: EC2DeployStack/EC2deployVpcParam
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/IGW
  EC2deployVpcParamVPCGW9A50FAD6:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId:
        Ref: EC2deployVpcParamIGW985AF470
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2deployVpcParam/VPCGW
  EC2SG244E8056:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow HTTP access
      SecurityGroupEgress:
        - CidrIp: 0.0.0.0/0
          Description: Allow all outbound traffic by default
          IpProtocol: "-1"
      VpcId:
        Ref: EC2deployVpcParamB91CBCEC
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2SG/Resource
  EC2SGfrom00000IndirectPortED96AD61:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      CidrIp: 0.0.0.0/0
      Description: Allow HTTP
      FromPort:
        Ref: ListenerPort
      GroupId:
        Fn::GetAtt:
          - EC2SG244E8056
          - GroupId
      IpProtocol: tcp
      ToPort:
        Ref: ListenerPort
    Metadata:
      aws:cdk:path: EC2DeployStack/EC2SG/from 0.0.0.0_0:{IndirectPort}
  InstanceRole3CCE2F1D:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ec2.amazonaws.com
        Version: "2012-10-17"
      Description: Role for EC2 instances to connect to SSM
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonSSMManagedInstanceCore
    Metadata:
      aws:cdk:path: EC2DeployStack/InstanceRole/Resource
  InstanceRoleDefaultPolicy1531605C:
    Type: AWS::IAM::Policy
    Properties:
      PolicyDocument:
        Statement:
          - Action:
              - ssm:GetParameter
              - ssm:GetParameters
            Effect: Allow
            Resource: "*"
        Version: "2012-10-17"
      PolicyName: InstanceRoleDefaultPolicy1531605C
      Roles:
        - Ref: InstanceRole3CCE2F1D
    Metadata:
      aws:cdk:path: EC2DeployStack/InstanceRole/DefaultPolicy/Resource
  WebsiteElasticIP:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
    Metadata:
      aws:cdk:path: EC2DeployStack/WebsiteElasticIP
  WebsiteInstanceInstanceProfileC9614704:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Roles:
        - Ref: InstanceRole3CCE2F1D
    Metadata:
      aws:cdk:path: EC2DeployStack/WebsiteInstance/InstanceProfile
  WebsiteInstance217C7E42:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone:
        Fn::Select:
          - 0
          - Fn::GetAZs: ""
      IamInstanceProfile:
        Ref: WebsiteInstanceInstanceProfileC9614704
      ImageId:
        Ref: SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter
      InstanceType: t3.micro
      KeyName:
        Ref: KeyName
      SecurityGroupIds:
        - Fn::GetAtt:
            - EC2SG244E8056
            - GroupId
      SubnetId:
        Ref: EC2deployVpcParamtemplatepublicSubnet1SubnetFCB7CF33
      Tags:
        - Key: Name
          Value: EC2DeployStack/WebsiteInstance
      UserData:
        Fn::Base64:
          Fn::Join:
            - ""
            - - |-
                #!/bin/bash
                #!/bin/bash
                set -e
                exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
                echo "开始执行用户数据脚本..."
                sudo yum update -y
                sudo yum install -y git
                if [ -f /etc/os-release ]; then
                    . /etc/os-release
                    if [[ "$VERSION_ID" == "2" ]]; then
                        # Amazon Linux 2
                        if command -v amazon-linux-extras >/dev/null 2>&1; then
                            sudo amazon-linux-extras install -y nginx1
                        else
                            # 如果 amazon-linux-extras 不可用，直接使用 yum
                            sudo yum install -y nginx
                        fi
                    else
                        # Amazon Linux 2023 或其他版本
                        sudo yum install -y nginx
                    fi
                else
                    # 默认安装方法
                    sudo yum install -y nginx
                fi
                sudo systemctl enable nginx
                sudo systemctl start nginx
                sudo mkdir -p /var/www/html
                sudo chown -R ec2-user:ec2-user /var/www/html
                sudo chmod -R 755 /var/www/html
                COMPANY_NAME="$(echo "
              - Ref: CompanyName
              - |-
                " | sed 's/["]/\&/g')"
                COMPANY_DESC="$(echo "
              - Ref: CompanyDescription
              - |-
                " | sed 's/["]/\&/g')"
                ABOUT_US="$(echo "
              - Ref: AboutUs
              - |-
                " | sed 's/["]/\&/g')"
                CORE_VALUES="$(echo "
              - Ref: CoreValues
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE1_TITLE="$(echo "
              - Ref: Service1Title
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE1_DESC="$(echo "
              - Ref: Service1Description
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE2_TITLE="$(echo "
              - Ref: Service2Title
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE2_DESC="$(echo "
              - Ref: Service2Description
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE3_TITLE="$(echo "
              - Ref: Service3Title
              - |-
                " | sed 's/["]/\&/g')"
                SERVICE3_DESC="$(echo "
              - Ref: Service3Description
              - |-
                " | sed 's/["]/\&/g')"
                COMPANY_EMAIL="$(echo "
              - Ref: CompanyEmail
              - |-
                " | sed 's/["]/\&/g')"
                COMPANY_PHONE="$(echo "
              - Ref: CompanyPhone
              - |-
                " | sed 's/["]/\&/g')"
                COMPANY_ADDRESS="$(echo "
              - Ref: CompanyAddress
              - |-
                " | sed 's/["]/\&/g')"
                CURRENT_YEAR="$(date +%Y)"
                cat > /var/www/html/index.html << EOF
                <!DOCTYPE html>
                <html lang="zh-CN">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>$COMPANY_NAME</title>
                    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
                    <style>
                        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
                        
                        * {
                            font-family: 'Inter', sans-serif;
                        }
                        
                        .hero {
                            background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://images.unsplash.com/photo-1504384308090-c894fdcc538d?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80');
                            background-size: cover;
                            background-position: center;
                            height: 100vh;
                        }
                        
                        .transition-nav {
                            transition: background-color 0.3s ease;
                        }
                        
                        .nav-scrolled {
                            background-color: white;
                            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
                        }
                        
                        .nav-scrolled .nav-link {
                            color: #1a202c;
                        }
                        
                        .nav-scrolled .logo {
                            color: #1a202c;
                        }
                        
                        .service-card {
                            transition: transform 0.3s ease, box-shadow 0.3s ease;
                        }
                        
                        .service-card:hover {
                            transform: translateY(-10px);
                            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
                        }
                        
                        .scroll-smooth {
                            scroll-behavior: smooth;
                        }
                    </style>
                </head>
                <body class="scroll-smooth">
                    <!-- 导航栏 -->
                    <nav id="navbar" class="fixed w-full z-50 transition-nav">
                        <div class="container mx-auto px-6 py-4">
                            <div class="flex justify-between items-center">
                                <a href="#" class="logo text-2xl font-bold text-white">$COMPANY_NAME</a>
                                <div class="hidden md:flex space-x-10">
                                    <a href="#home" class="nav-link text-white hover:text-gray-300 transition duration-300">首页</a>
                                    <a href="#about" class="nav-link text-white hover:text-gray-300 transition duration-300">关于我们</a>
                                    <a href="#services" class="nav-link text-white hover:text-gray-300 transition duration-300">服务</a>
                                    <a href="#contact" class="nav-link text-white hover:text-gray-300 transition duration-300">联系我们</a>
                                </div>
                                <div class="md:hidden">
                                    <button id="menu-toggle" class="text-white focus:outline-none">
                                        <svg class="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
                                        </svg>
                                    </button>
                                </div>
                            </div>
                            <div id="mobile-menu" class="md:hidden hidden pt-4">
                                <a href="#home" class="block py-2 text-white hover:text-gray-300">首页</a>
                                <a href="#about" class="block py-2 text-white hover:text-gray-300">关于我们</a>
                                <a href="#services" class="block py-2 text-white hover:text-gray-300">服务</a>
                                <a href="#contact" class="block py-2 text-white hover:text-gray-300">联系我们</a>
                            </div>
                        </div>
                    </nav>

                    <!-- 首页/英雄区域 -->
                    <section id="home" class="hero flex items-center">
                        <div class="container mx-auto px-6 text-center">
                            <h1 class="text-5xl md:text-6xl font-bold text-white mb-6">$COMPANY_NAME</h1>
                            <p class="text-xl md:text-2xl text-white mb-10 max-w-3xl mx-auto">$COMPANY_DESC</p>
                            <a href="#contact" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-8 rounded-full text-lg transition duration-300 transform hover:scale-105">联系我们</a>
                        </div>
                    </section>

                    <!-- 关于我们 -->
                    <section id="about" class="py-20 bg-white">
                        <div class="container mx-auto px-6">
                            <div class="text-center mb-16">
                                <h2 class="text-4xl font-bold text-gray-800 mb-4">关于我们</h2>
                                <div class="w-24 h-1 bg-blue-600 mx-auto"></div>
                            </div>
                            <div class="flex flex-wrap items-center">
                                <div class="w-full md:w-1/2 mb-10 md:mb-0">
                                    <img src="https://images.unsplash.com/photo-1552664730-d307ca884978?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80" alt="关于我们" class="rounded-lg shadow-xl">
                                </div>
                                <div class="w-full md:w-1/2 md:pl-10">
                                    <!-- <p class="text-lg text-gray-700 mb-6">$COMPANY_DESC</p> -->
                                    <p class="text-lg text-gray-700 mb-6">$ABOUT_US</p>
                                    <p class="text-lg text-gray-700">$CORE_VALUES</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- 服务 -->
                    <section id="services" class="py-20 bg-gray-100">
                        <div class="container mx-auto px-6">
                            <div class="text-center mb-16">
                                <h2 class="text-4xl font-bold text-gray-800 mb-4">我们的服务</h2>
                                <div class="w-24 h-1 bg-blue-600 mx-auto"></div>
                            </div>
                            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10">
                                <div class="service-card bg-white rounded-lg shadow-lg p-8">
                                    <div class="text-blue-600 text-5xl mb-6">
                                        <svg class="w-16 h-16" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path fill-rule="evenodd" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z" clip-rule="evenodd"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold text-gray-800 mb-4">$SERVICE1_TITLE</h3>
                                    <p class="text-gray-700">$SERVICE1_DESC</p>
                                </div>
                                <div class="service-card bg-white rounded-lg shadow-lg p-8">
                                    <div class="text-blue-600 text-5xl mb-6">
                                        <svg class="w-16 h-16" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v3h8v-3zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-3a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v3h-3zM4.75 12.094A5.973 5.973 0 004 15v3H1v-3a3 3 0 013.75-2.906z"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold text-gray-800 mb-4">$SERVICE2_TITLE</h3>
                                    <p class="text-gray-700">$SERVICE2_DESC</p>
                                </div>
                                <div class="service-card bg-white rounded-lg shadow-lg p-8">
                                    <div class="text-blue-600 text-5xl mb-6">
                                        <svg class="w-16 h-16" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path fill-rule="evenodd" d="M6 6V5a3 3 0 013-3h2a3 3 0 013 3v1h2a2 2 0 012 2v3.57A22.952 22.952 0 0110 13a22.95 22.95 0 01-8-1.43V8a2 2 0 012-2h2zm2-1a1 1 0 011-1h2a1 1 0 011 1v1H8V5zm1 5a1 1 0 011-1h.01a1 1 0 110 2H10a1 1 0 01-1-1z" clip-rule="evenodd"></path>
                                            <path d="M2 13.692V16a2 2 0 002 2h12a2 2 0 002-2v-2.308A24.974 24.974 0 0110 15c-2.796 0-5.487-.46-8-1.308z"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold text-gray-800 mb-4">$SERVICE3_TITLE</h3>
                                    <p class="text-gray-700">$SERVICE3_DESC</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- 联系我们 -->
                    <section id="contact" class="py-20 bg-blue-900 text-white">
                        <div class="container mx-auto px-6">
                            <div class="text-center mb-16">
                                <h2 class="text-4xl font-bold mb-4">联系我们</h2>
                                <div class="w-24 h-1 bg-white mx-auto"></div>
                            </div>
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-10 text-center">
                                <div class="p-6">
                                    <div class="text-5xl mb-6">
                                        <svg class="w-16 h-16 mx-auto" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z"></path>
                                            <path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold mb-4">邮箱</h3>
                                    <p>$COMPANY_EMAIL</p>
                                </div>
                                <div class="p-6">
                                    <div class="text-5xl mb-6">
                                        <svg class="w-16 h-16 mx-auto" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path d="M2 3a1 1 0 011-1h2.153a1 1 0 01.986.836l.74 4.435a1 1 0 01-.54 1.06l-1.548.773a11.037 11.037 0 006.105 6.105l.774-1.548a1 1 0 011.059-.54l4.435.74a1 1 0 01.836.986V17a1 1 0 01-1 1h-2C7.82 18 2 12.18 2 5V3z"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold mb-4">电话</h3>
                                    <p>$COMPANY_PHONE</p>
                                </div>
                                <div class="p-6">
                                    <div class="text-5xl mb-6">
                                        <svg class="w-16 h-16 mx-auto" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
                                            <path fill-rule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clip-rule="evenodd"></path>
                                        </svg>
                                    </div>
                                    <h3 class="text-2xl font-bold mb-4">地址</h3>
                                    <p>$COMPANY_ADDRESS</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- 页脚 -->
                    <footer class="bg-gray-900 text-white py-10">
                        <div class="container mx-auto px-6 text-center">
                            <p>&copy; $CURRENT_YEAR $COMPANY_NAME. 保留所有权利。</p>
                        </div>
                    </footer>

                    <script>
                        // 导航栏滚动效果
                        window.addEventListener('scroll', function() {
                            const navbar = document.getElementById('navbar');
                            if (window.scrollY > 50) {
                                navbar.classList.add('nav-scrolled');
                            } else {
                                navbar.classList.remove('nav-scrolled');
                            }
                        });

                        // 移动端菜单切换
                        document.getElementById('menu-toggle').addEventListener('click', function() {
                            const mobileMenu = document.getElementById('mobile-menu');
                            mobileMenu.classList.toggle('hidden');
                        });

                        // 平滑滚动
                        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
                            anchor.addEventListener('click', function (e) {
                                e.preventDefault();
                                
                                const mobileMenu = document.getElementById('mobile-menu');
                                if (!mobileMenu.classList.contains('hidden')) {
                                    mobileMenu.classList.add('hidden');
                                }
                                
                                document.querySelector(this.getAttribute('href')).scrollIntoView({
                                    behavior: 'smooth'
                                });
                            });
                        });
                    </script>
                </body>
                </html>

                EOF
                sudo rm -rf /usr/share/nginx/html/*
                sudo cp -r /var/www/html/* /usr/share/nginx/html/
                sudo tee /etc/nginx/conf.d/website.conf > /dev/null << EOF
                server {
                    listen 8001;
                    server_name _;
                    root /usr/share/nginx/html;
                    index index.html;

                    location / {
                        try_files \$uri \$uri/ /index.html;
                    }
                }
                EOF
                sudo systemctl restart nginx
    DependsOn:
      - InstanceRoleDefaultPolicy1531605C
      - InstanceRole3CCE2F1D
    Metadata:
      aws:cdk:path: EC2DeployStack/WebsiteInstance/Resource
  ElasticIPAssociation:
    Type: AWS::EC2::EIPAssociation
    Properties:
      AllocationId:
        Fn::GetAtt:
          - WebsiteElasticIP
          - AllocationId
      InstanceId:
        Ref: WebsiteInstance217C7E42
    Metadata:
      aws:cdk:path: EC2DeployStack/ElasticIPAssociation
Outputs:
  ElasticIP:
    Description: ElasticIP address of your EC2
    Value:
      Ref: WebsiteElasticIP
  WebsiteURL:
    Description: Your campany website URL
    Value:
      Fn::Join:
        - ""
        - - http://
          - Ref: WebsiteElasticIP
          - ":"
          - Ref: ListenerPort
Conditions:
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - af-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-3
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-3
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-4
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-south-2
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - il-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
      - Fn::Equals:
          - Ref: AWS::Region
          - us-west-2

