Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handler(event, context):
"""
Main handler function, passes off it's work to crhelper's cfn_handler
"""
# update the logger with event info
global logger
logger = crhelper.log_config(event)
return crhelper.cfn_handler(event, context, create, update, delete, logger,
init_failed)
def handler(event, context):
"""Main handler function, passes off it's work to crhelper's cfn_handler.""" # noqa: D401
# update the logger with event info
global logger
logger = crhelper.log_config(event, loglevel="info")
return crhelper.cfn_handler(event, context, create, update, delete, logger, init_failed)
# Copyright 2018 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://aws.amazon.com/apache2.0/
#
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
# limitations under the License.
import boto3
import crhelper
# initialise logger
logger = crhelper.log_config({"RequestId": "CONTAINER_INIT"})
logger.info("Logging configured")
# set global to track init failures
init_failed = False
try:
# Place initialization code here
logger.info("Container initialization completed")
except Exception as e:
logger.error(e, exc_info=True)
init_failed = e
def delete_s3_bucket(bucket_name):
"""
Empty and delete the bucket passed as argument.
# Copyright 2018 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://aws.amazon.com/apache2.0/
#
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
# limitations under the License.
import boto3
import crhelper
# initialise logger
logger = crhelper.log_config({"RequestId": "CONTAINER_INIT"})
logger.info("Logging configured")
# set global to track init failures
init_failed = False
try:
# Place initialization code here
logger.info("Container initialization completed")
except Exception as e:
logger.error(e, exc_info=True)
init_failed = e
def trigger_codebuild(project_name):
"""
Start a build for a specific CodeBuild project.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
##################################################################################################
from __future__ import print_function
import time
import boto3
import crhelper
# initialise logger
logger = crhelper.log_config({"RequestId": "CONTAINER_INIT"})
logger.info('Logging configured')
# set global to track init failures
init_failed = False
try:
# Place initialization code here
client = boto3.client('ec2')
logger.info("Container initialization completed")
except Exception as e:
logger.error(e, exc_info=True)
init_failed = e
def get_instance(instance_name):
while True:
response = client.describe_instances(Filters=[{'Name': 'tag:Name', 'Values': [instance_name]}])