Skip to content

Instantly share code, notes, and snippets.

@dgtm
Created May 17, 2021 21:35
Show Gist options
  • Save dgtm/5def4afd12a4d15a3314053a37619af7 to your computer and use it in GitHub Desktop.
Save dgtm/5def4afd12a4d15a3314053a37619af7 to your computer and use it in GitHub Desktop.
error
cfn-init --stack asds --resource bbbInstance --configsets full_install --region us-east-1
+ cfn-init --stack asds --resource bbbInstance --configsets full_install --region us-east-1
Cloud-init v. 20.2-45-g5f7825e2-0ubuntu1~16.04.1 running 'modules:final' at Mon, 17 May 2021 21:16:42 +0000. Up 30.32 seconds.
2021-05-17 21:17:19,013 - util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
2021-05-17 21:17:19,015 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2021-05-17 21:17:19,016 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed
Cloud-init v. 20.2-45-g5f7825e2-0ubuntu1~16.04.1 finished at Mon, 17 May 2021 21:17:19 +0000. Datasource DataSourceEc2Local. Up 66.92 seconds
@dgtm
Copy link
Author

dgtm commented May 17, 2021

---
AWSTemplateFormatVersion: "2010-09-09"

Description: >
  This CFN creates an instance with BigBlueButton installed

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      -
        Label:
          default: "Network Configuration"
        Parameters:
          - AssociatedVPC
          - PublicSubnet
      -
        Label:
          default: "Amazon Ec2 Configuration"
        Parameters:
          - KeyPair
          - ElasticIpAllocationID
      -
        Label:
          default: "BigBlueButton Configuration"
        Parameters:
          - Email
          - Username
          - Password
          - SubDomain

Parameters:
  SubDomain:
    Type: String
    Description: Please enter your BigBlueButton Subdomain (FQDN)
    AllowedPattern: ".+"
    ConstraintDescription: Please enter a valid domain name
  KeyPair:
    Type: AWS::EC2::KeyPair::KeyName
    Description: Select your KeyPair to SSH into the instance
    AllowedPattern: ".+"
    ConstraintDescription: Please enter a valid value
  Email:
    Type: String
    Description: Enter your email address
    AllowedPattern: '.+'
    ConstraintDescription: Please provide a valid entry
  Username:
    Type: String
    Description: Please enter an admin username
    AllowedPattern: ".+"
    ConstraintDescription: Please provide a valid entry
  Password:
    Type: String
    Description: Please enter admin password (Minimum 8 characters)
    AllowedPattern: ".+"
    ConstraintDescription: Please provide a valid entry
    NoEcho: true
  AssociatedVPC:
    Type: AWS::EC2::VPC::Id
    Description: Select your VPC with public subnet
    AllowedPattern: ".+"
    ConstraintDescription: Please provide a valid entry
  PublicSubnet:
    Type: AWS::EC2::Subnet::Id
    Description: Choose a public subnet in the selected VPC
    AllowedPattern: ".+"
    ConstraintDescription: Please provide a valid entry
  ElasticIpAllocationID:
    Type: String
    Description: Please enter the EIP Allocation ID (eipalloc-xxxxxxxxxxxxxxx).
    AllowedPattern: ".+"
    ConstraintDescription: Please enter a valid EIP allocation ID

Mappings:
  RegionMap:
    us-east-1:
      AMI: "ami-05e16100b6f337dda"
    us-west-1:
      AMI: "ami-0a63cd87767e10ed4"
    us-west-2:
      AMI: "ami-0807918df10edc141"
    eu-west-1:
      AMI: "ami-0a74b2559fb675b98"
    sa-east-1:
      AMI: "ami-0a6397d8b6239f6ad"
    ap-southeast-1:
      AMI: "ami-099e6eeef1c3dac48"
    ap-southeast-2:
      AMI: "ami-0dd7583b0a983a748"
    ap-northeast-1:
      AMI: "ami-0edf7f6a9013cfb72"
    ap-south-1:
      AMI: "ami-08e76c6a76ebf6433"

#Conditions:

Resources:
  bbbSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
        GroupDescription: Allow specific ports
        VpcId:
           Ref: AssociatedVPC
        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
        - IpProtocol: tcp
          FromPort: 443
          ToPort: 443
          CidrIp: 0.0.0.0/0
        - IpProtocol: udp
          FromPort: 16384
          ToPort: 32768
          CidrIp: 0.0.0.0/0

  RoleForInstance:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          -
            Effect: "Allow"
            Principal:
              Service:
                - "ec2.amazonaws.com"
            Action:
              - "sts:AssumeRole"
  RolePolicies:
    Type: "AWS::IAM::Policy"
    Properties:
      PolicyName: "attachEipPolicy"
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          -
            Effect: "Allow"
            Action: "ec2:AssociateAddress"
            Resource: "*"
      Roles:
        -
          Ref: "RoleForInstance"
  Ec2InstanceProfile:
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Path: "/"
      Roles:
        -
          Ref: "RoleForInstance"

  bbbInstance:
    Type: AWS::EC2::Instance
    CreationPolicy:
      ResourceSignal:
        Timeout: PT45M
        Count: '1'
    Metadata:
      'AWS::CloudFormation::Init':
        configSets:
          full_install:
            - install_and_setup_bbb
        install_and_setup_bbb:
          commands:
            01associate_address:
              command:
                Fn::Join:
                  - ''
                  - - 'aws ec2 associate-address --allocation-id '
                    - !Ref 'ElasticIpAllocationID'
                    - ' --instance-id '
                    - '$(curl http://169.254.169.254/latest/meta-data/instance-id)'
                    - ' --region '
                    - !Ref 'AWS::Region'
            02install_bbb:
              cwd: /root
              command:
                Fn::Join:
                  - ''
                  - - 'wget -qO- https://ubuntu.bigbluebutton.org/bbb-install.sh | bash -s -- -v xenial-22 -s '
                    - !Ref 'SubDomain'
                    - ' -e '
                    - !Ref 'Email'
                    - ' -w -g'
            03create_admin_user:
              cwd: /root/greenlight
              command:
                Fn::Join:
                  - ''
                  - - 'docker exec greenlight-v2 bundle exec rake user:create['
                    - '"'
                    - !Ref 'Username'
                    - '","'
                    - !Ref 'Email'
                    - '","'
                    - !Ref 'Password'
                    - '","'
                    - 'admin"]'
    Properties:
      IamInstanceProfile:
        Ref: Ec2InstanceProfile
      BlockDeviceMappings:
        - DeviceName: /dev/sda1
          Ebs:
            VolumeSize: 100
      ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
      InstanceType: c5.xlarge
      SubnetId:
        Ref: PublicSubnet
      KeyName:
        Ref: KeyPair
      SecurityGroupIds:
        - Fn::GetAtt: [ bbbSecurityGroup, GroupId ]
      Tags:
        - Key: Name
          Value: BigBlueButton
      UserData: !Base64
        'Fn::Join':
          - ''
          - - |
              #!/bin/bash -xev
            - |
              apt-get update -y
            - |
              apt-get install -y python-setuptools awscli python-pystache heat-cfntools
            - |
              mkdir -p /opt/aws/bin
            - |
              cat /var/lib/cloud/instance/scripts/part-001
            - |
              ls -la /var/lib/cloud/instance/scripts/part-001
            - |
              chmod +x /var/lib/cloud/instance/scripts/part-001
            - |+

            - 'cfn-init'
            - '         --stack '
            - !Ref 'AWS::StackName'
            - '         --resource  bbbInstance'
            - '         --configsets full_install '
            - '         --region '
            - !Ref 'AWS::Region'
            - |+

            - 'cfn-signal -e $? '
            - '         --stack '
            - !Ref 'AWS::StackName'
            - '         --resource bbbInstance '
            - '         --region '
            - !Ref 'AWS::Region'
            - |+

  #ElasticIpAddress:
  #  Type: AWS::EC2::EIPAssociation
  #  Properties:
  #    AllocationId:
  #      Ref: ElasticIp
  #    InstanceId:
  #      Ref: bbbInstance

Outputs:
  Endpoint:
    Description: Endpoint
    Value:
      Ref: SubDomain

@dgtm
Copy link
Author

dgtm commented May 17, 2021

@RohitRox
Copy link

RohitRox commented May 18, 2021

Makefile

MAKE_ARGS=--profile $(AWS_PROFILE) --region $(AWS_REGION)

VPC_ID=	
PUBLIC_SUBNET=

create-vpc:
	aws cloudformation create-stack --stack-name bbb-vpc --template-body file://vpc.yaml $(MAKE_ARGS)
create-bbb:
	aws cloudformation create-stack --stack-name bbb-stack --template-body file://bigbluebutton.yaml $(MAKE_ARGS) --parameters \
	ParameterKey=AssociatedVPC,ParameterValue=$(VPC_ID) \
	ParameterKey=PublicSubnet,ParameterValue=$(PUBLIC_SUBNET) \
	ParameterKey=PublicSubnet,ParameterValue=$(PUBLIC_SUBNET) \
	ParameterKey=Email,ParameterValue=hello@gmail.com \
	ParameterKey=Username,ParameterValue=hello123 \
	ParameterKey=Password,ParameterValue=Password@1 \
	ParameterKey=KeyPair,ParameterValue=key-bbb

update-stack:
	aws cloudformation update-stack --stack-name bbb-stack --template-body file://bigbluebutton.yaml $(MAKE_ARGS) --parameters \
	ParameterKey=AssociatedVPC,ParameterValue=$(VPC_ID) \
	ParameterKey=PublicSubnet,ParameterValue=$(PUBLIC_SUBNET) \
	ParameterKey=PublicSubnet,ParameterValue=$(PUBLIC_SUBNET) \
	ParameterKey=Email,ParameterValue=hello@gmail.com \
	ParameterKey=Username,ParameterValue=hello123 \
	ParameterKey=Password,ParameterValue=Password@1 \
	ParameterKey=KeyPair,ParameterValue=key-bbb 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment