예제 #1
0
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import os
import time
import json
import re
import logging as log
from awsutil import get_client

REGION = os.environ["REGION"]
AUTO_SCALING_GROUP_NAME = os.environ["AUTO_SCALING_GROUP_NAME"]
ec2as = get_client("autoscaling")
ssm = get_client("ssm")


def get_instance_id():
    asg = ec2as.describe_auto_scaling_groups(
        AutoScalingGroupNames=[AUTO_SCALING_GROUP_NAME])
    healthy = [
        i for i in asg["AutoScalingGroups"][0]["Instances"]
        if i["HealthStatus"] == "Healthy"
    ]
    if len(healthy) == 0:
        raise Exception("No healthy instances.")
    return healthy[0]["InstanceId"]

예제 #2
0
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import time
from awsutil import get_client

logs = get_client("logs")


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
        return on_delete(event)
    raise Exception("Invalid request type: %s" % request_type)


def on_delete(event):
    props = event["ResourceProperties"]
예제 #3
0
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
from awsutil import get_client

iot = get_client("iot")


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
        return on_delete(event)
    raise Exception("Invalid request type: %s" % request_type)


def on_delete(event):
    return {"PhysicalResourceId": ""}
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import time
from awsutil import get_client

ec2as = get_client("autoscaling")


def assertHealthCheckGracePeriodIs2Mins(asgName):
    ec2as.update_auto_scaling_group(
        AutoScalingGroupName=asgName, HealthCheckGracePeriod=90
    )


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import logging as log
from awsutil import get_client
import ipaddress

ga = get_client("globalaccelerator")
ec2 = get_client("ec2")
r53r = get_client("route53resolver")


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
        return on_delete(event)
    raise Exception("Invalid request type: %s" % request_type)

import boto3
import json
import os
from datetime import datetime, timedelta
import urllib
import logging as log
from awsutil import get_client

REGION = os.environ["REGION"]
STACK_NAME = os.environ["STACK_NAME"]
SOLUTION_ID = os.environ["SOLUTION_ID"]
PERIOD_SECONDS = int(os.environ["PERIOD_SECONDS"])
SEND_USAGE_DATA = os.environ["SEND_USAGE_DATA"] == "Yes"

cloudwatch = get_client("cloudwatch")
cfn = get_client("cloudformation")


def send(payload):
    if not SEND_USAGE_DATA:
        log.info("Anonymous data collection not activated, skipping send")
        return

    log.info("Anonymous data payload")
    log.info(json.dumps(payload))
    req = urllib.request.Request(
        method="POST",
        url=f"https://{os.environ['ENDPOINT']}/generic",
        data=json.dumps(payload).encode("utf-8"),
        headers={"content-type": "application/json"},
예제 #7
0
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import time
import logging as log
from awsutil import get_client

efs = get_client("efs")


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
        return on_delete(event)
    raise Exception("Invalid request type: %s" % request_type)


def on_delete(event):
    props = event["ResourceProperties"]
예제 #8
0
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is located at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
#

import boto3
import time
import logging as log
from awsutil import get_client

ec2 = get_client("ec2")


def handler(event, context):
    request_type = event["RequestType"]
    if request_type == "Create":
        return on_create(event)
    if request_type == "Update":
        return on_update(event)
    if request_type == "Delete":
        return on_delete(event)
    raise Exception("Invalid request type: %s" % request_type)


def on_delete(event):
    props = event["ResourceProperties"]