コード例 #1
0
def create_launch_template(user_data_file, template_name=None):

    aws = AWS_CREDS(aws_profile)
    ec2_inst = EC2_instance()
    """ These are all the groups          """
    """ Needs to be different for FlyWheel """

    if template_name:
        fly_id = aws.ec2_res.meta.client.describe_security_groups(
            Filters=[{
                "Name": "group-name",
                "Values": ["FlyWheel"]
            }])["SecurityGroups"][0]["GroupId"]
        ssh_id = aws.ec2_res.meta.client.describe_security_groups(
            Filters=[{
                "Name": "group-name",
                "Values": ["SSH"]
            }])["SecurityGroups"][0]["GroupId"]
        if template_name == "FlyWheel":
            sec_group_ids = [fly_id, ssh_id]
        else:
            sec_group_ids = [
                x["GroupId"]
                for x in aws.ec2_res.meta.client.describe_security_groups()
                ["SecurityGroups"] if x["GroupId"] != fly_id
            ]

    try:
        user_data = open(user_data_file, "r").read().encode("utf-8")
    except OSError as e:
        print("Try another file: ", e)
        sys.exit(1)

    encoded_user_data = base64.b64encode(user_data)
    str_encoded_user_data = encoded_user_data.decode("ascii")

    INSTANCE_PROFILE = inst_profiles[0]
    AMI = ec2_inst.ami
    LAUNCH_TEMPLATE = template_name or ec2_inst.lt_name
    INSTANCE_TYPE = ec2_inst.type
    VPCID = aws.ec2_res.meta.client.describe_vpcs()["Vpcs"][0]["VpcId"]
    KEYNAME = f"{VPCID}-{aws_profile}.pem"

    return aws.ec2_res.meta.client.create_launch_template(
        LaunchTemplateName=LAUNCH_TEMPLATE,
        LaunchTemplateData={
            "EbsOptimized": False,
            "IamInstanceProfile": {
                "Name": INSTANCE_PROFILE
            },
            "ImageId": AMI,
            "InstanceType": INSTANCE_TYPE,
            "KeyName": KEYNAME,
            "Monitoring": {
                "Enabled": True
            },
            "SecurityGroupIds": sec_group_ids,
            "UserData": str_encoded_user_data,
        },
    )
コード例 #2
0
#!/usr/bin/env python3

from aws_cred_objects import AWS_CREDS
from prod_build_config import aws_profile

import boto3

"""

Cert Data will look like this:
{'CertificateSummaryList': [{'CertificateArn': 'CERT_ARN', 'DomainName': 'WWW'}], BLAH.....}

"""

aws_creds = AWS_CREDS(profile_name=aws_profile)


def get_cert_arn():
    return aws_creds.acm_client.list_certificates()["CertificateSummaryList"][0][
        "CertificateArn"
    ]


if __name__ == "__main__":
    print(get_cert_arn())
コード例 #3
0
from prod_build_config import aws_profile, inst_profiles
from aws_cred_objects import AWS_CREDS


def launch(name, version, subnet_id, max=1, min=1):

    print(
        aws.ec2_res.create_instances(
            LaunchTemplate={
                "LaunchTemplateName": name,
                "Version": str(version)
            },
            SubnetId=subnet_id,
            MinCount=min,
            MaxCount=max,
        ))


if __name__ == "__main__":

    aws = AWS_CREDS(aws_profile)
    subnet_id = random.choice(list(aws.ec2_res.subnets.all())).id
    # launch("Auto-Scaling-Launch-Template-Base", 1, subnet_id)
    # launch("HTTP", 1, subnet_id)
    launch("FlyWheel", 1, subnet_id)
    launch("Crawler", 1, subnet_id)
    # launch("Crawler", 1, subnet_id,min=50,max=50)
    # launch("Crawler", 1, subnet_id,min=25,max=35)
    # Add instance ip to mongodb
    # Add flywheel ip to instance
コード例 #4
0
ファイル: prod_vpc_lb_builder.py プロジェクト: jouellnyc/AWS
                        "Host": web_site_name,
                        "Path": "/#{path}",
                        "Query": "#{query}",
                        "StatusCode": self.myLoadBalancer.redirect_status_code,
                    },
                }],
            )
        except Exception as e:
            logging.exception(f"LB problem: {e}")
        else:
            print(f"LB: Target Group {FirstTg_Group} attached to {LBName} OK")


if __name__ == "__main__":

    aws_creds = AWS_CREDS(aws_profile)
    prod_vpc = BUILD(aws_creds, VPC)
    print("Profile: ", aws_profile)

    print(prod_vpc.my_create_vpc(tagged=True))
    for subnet_bundle in subnet_bundles:
        prod_vpc.my_create_subnet(subnet_bundle)
    prod_vpc.my_create_igw()
    prod_vpc.my_create_routes()
    prod_vpc.my_create_keypair()
    for sec_group in sec_groups:
        prod_vpc.my_create_security_groups(sec_group)
    for inst_prof_name in inst_profiles:
        prod_vpc.my_create_instance_profile(inst_prof_name)
    for role_name, role_file in roles:
        prod_vpc.my_create_app_role(role_name, role_file)