def test_get_boto_session(self, Session): """ get_boto_session should call Session with the current app's config """ instance = Session.return_value app_ = app.create_app() app_.config["AWS_REGION"] = "unittest-region" app_.config["AWS_ACCESS_KEY"] = "unittest-access" app_.config["AWS_SECRET_KEY"] = "unittest-secret" with self.assertRaises(RuntimeError): # app-context must be available get_boto_session() with app_.app_context(): get_boto_session() Session.assert_called_with( aws_access_key_id="unittest-access", aws_secret_access_key="unittest-secret", region_name="unittest-region" )
def test_get_boto_session(self, Session): """ get_boto_session should call Session with the current app's config """ app_ = app.create_app() app_.config['AWS_REGION'] = "unittest-region" app_.config['AWS_ACCESS_KEY'] = "unittest-access" app_.config['AWS_SECRET_KEY'] = "unittest-secret" with self.assertRaises(RuntimeError): # app-context must be available get_boto_session() with app_.app_context(): get_boto_session() Session.assert_called_with( aws_access_key_id="unittest-access", aws_secret_access_key="unittest-secret", region_name="unittest-region", )
def register_task_revision(ecsbuild): """ Calls the registerTaskDefinition aws-api endpoint to update a task definition based on the ECSBuild. This must be called within an app context. :param ecsbuild: the dockerrun.aws.json, represented as a ECSBuild or a JSON-formatted string :type ecsbuild: mc.builders.ECSBuild or basestring """ client = get_boto_session().client('ecs') if isinstance(ecsbuild, basestring): payload = ecsbuild else: payload = ecsbuild.render_template() client.register_task_definition(**json.loads(payload))
def update_service(cluster, service, desiredCount, taskDefinition): """ Thin wrapper around boto3 ecs.update_service; # http://boto3.readthedocs.org/en/latest/reference/services/ecs.html#ECS.Client.update_service :param cluster: The short name or full Amazon Resource Name (ARN) of the cluster that your service is running on. If you do not specify a cluster, the default cluster is assumed. :param service: The name of the service that you want to update. :param desiredCount: The number of instantiations of the task that you would like to place and keep running in your service. :param taskDefinition: The family and revision (family:revision ) or full Amazon Resource Name (ARN) of the task definition that you want to run in your service. If a revision is not specified, the latest ACTIVE revision is used. If you modify the task definition with UpdateService , Amazon ECS spawns a task with the new version of the task definition and then stops an old task after the new version is running. """ client = get_boto_session().client('ecs') client.update_service( cluster=cluster, service=service, desiredCount=desiredCount, taskDefinition=taskDefinition )