import boto3


def create_session(profile_name):
    if not profile_name:
        return boto3
    else:
        return boto3.Session(profile_name=profile_name)

import sys

import boto3
import botocore
import click


def create_session(profile_name):
    if profile_name is None:
        return boto3
    else:
        try:
            session = boto3.Session(profile_name=profile_name)
            return session
        except botocore.exceptions.ProfileNotFound as e:
            click.echo("Invalid profile name: {0}".format(profile_name, e), err=True)
            sys.exit(2)

Add error message when wrong AWS Profile Name is given
Add error message when wrong AWS Profile Name is given

+ import sys
+ 
  import boto3
+ import botocore
+ import click
  
  
  def create_session(profile_name):
-     if not profile_name:
+     if profile_name is None:
          return boto3
      else:
+         try:
-         return boto3.Session(profile_name=profile_name)
+             session = boto3.Session(profile_name=profile_name)
+             return session
+         except botocore.exceptions.ProfileNotFound as e:
+             click.echo("Invalid profile name: {0}".format(profile_name, e), err=True)
+             sys.exit(2)
  
Add error message when wrong AWS Profile Name is given
## Code Before:
import boto3


def create_session(profile_name):
    if not profile_name:
        return boto3
    else:
        return boto3.Session(profile_name=profile_name)

## Instruction:
Add error message when wrong AWS Profile Name is given
## Code After:
import sys

import boto3
import botocore
import click


def create_session(profile_name):
    if profile_name is None:
        return boto3
    else:
        try:
            session = boto3.Session(profile_name=profile_name)
            return session
        except botocore.exceptions.ProfileNotFound as e:
            click.echo("Invalid profile name: {0}".format(profile_name, e), err=True)
            sys.exit(2)
