
import json

import boto3


def change_desired_count(cluster, service, desired_count):
    """
    Given an ECS cluster, service name and desired instance count, change
    the instance count on AWS.
    """
    ecs = boto3.client('ecs')
    resp = ecs.update_service(
        cluster=cluster,
        service=service,
        desiredCount=desired_count
    )
    print('ECS response: %r' % resp)
    assert resp['ResponseMetadata']['HTTPStatusCode'] == 200


def main(event, _):
    print('Received event: %r' % event)
    message = event['Message']
    message_data = json.loads(message)

    change_desired_count(
        cluster=message_data['cluster'],
        service=message_data['service'],
        desired_count=message_data['desired_count']
    )


import json

import boto3


def change_desired_count(cluster, service, desired_count):
    """
    Given an ECS cluster, service name and desired instance count, change
    the instance count on AWS.
    """
    ecs = boto3.client('ecs')
    resp = ecs.update_service(
        cluster=cluster,
        service=service,
        desiredCount=desired_count
    )
    print('ECS response: %r' % resp)
    assert resp['ResponseMetadata']['HTTPStatusCode'] == 200


def main(event, _):
    print('Received event: %r' % event)
    message = event['Records'][0]['Sns']['Message']
    message_data = json.loads(message)

    change_desired_count(
        cluster=message_data['cluster'],
        service=message_data['service'],
        desired_count=message_data['desired_count']
    )

Fix the Update ECS Service size Lambda
Fix the Update ECS Service size Lambda

  
  import json
  
  import boto3
  
  
  def change_desired_count(cluster, service, desired_count):
      """
      Given an ECS cluster, service name and desired instance count, change
      the instance count on AWS.
      """
      ecs = boto3.client('ecs')
      resp = ecs.update_service(
          cluster=cluster,
          service=service,
          desiredCount=desired_count
      )
      print('ECS response: %r' % resp)
      assert resp['ResponseMetadata']['HTTPStatusCode'] == 200
  
  
  def main(event, _):
      print('Received event: %r' % event)
-     message = event['Message']
+     message = event['Records'][0]['Sns']['Message']
      message_data = json.loads(message)
  
      change_desired_count(
          cluster=message_data['cluster'],
          service=message_data['service'],
          desired_count=message_data['desired_count']
      )
  
Fix the Update ECS Service size Lambda
## Code Before:

import json

import boto3


def change_desired_count(cluster, service, desired_count):
    """
    Given an ECS cluster, service name and desired instance count, change
    the instance count on AWS.
    """
    ecs = boto3.client('ecs')
    resp = ecs.update_service(
        cluster=cluster,
        service=service,
        desiredCount=desired_count
    )
    print('ECS response: %r' % resp)
    assert resp['ResponseMetadata']['HTTPStatusCode'] == 200


def main(event, _):
    print('Received event: %r' % event)
    message = event['Message']
    message_data = json.loads(message)

    change_desired_count(
        cluster=message_data['cluster'],
        service=message_data['service'],
        desired_count=message_data['desired_count']
    )

## Instruction:
Fix the Update ECS Service size Lambda
## Code After:

import json

import boto3


def change_desired_count(cluster, service, desired_count):
    """
    Given an ECS cluster, service name and desired instance count, change
    the instance count on AWS.
    """
    ecs = boto3.client('ecs')
    resp = ecs.update_service(
        cluster=cluster,
        service=service,
        desiredCount=desired_count
    )
    print('ECS response: %r' % resp)
    assert resp['ResponseMetadata']['HTTPStatusCode'] == 200


def main(event, _):
    print('Received event: %r' % event)
    message = event['Records'][0]['Sns']['Message']
    message_data = json.loads(message)

    change_desired_count(
        cluster=message_data['cluster'],
        service=message_data['service'],
        desired_count=message_data['desired_count']
    )
