def create_lambda()

in sagemaker_run_notebook/run_notebook.py [0:0]


def create_lambda(role=None, session=None):
    session = ensure_session(session)
    created = False

    if role is None:
        print(
            "No role specified, will create a minimal role and policy to execute the lambda"
        )
        role = create_lambda_role()
        created = True
        # time.sleep(30) # wait for eventual consistency, we hope

    if "/" not in role:
        account = session.client("sts").get_caller_identity()["Account"]
        role = "arn:aws:iam::{}:role/{}".format(account, role)

    code_bytes = zip_bytes(code_file)

    client = session.client("lambda")

    print("Role={}".format(role))
    retries = 0
    while True:
        try:
            result = client.create_function(
                FunctionName=lambda_function_name,
                Runtime="python3.8",
                Role=role,
                Handler="lambda_function.lambda_handler",
                Code={"ZipFile": code_bytes},
                Description=lambda_description,
                Timeout=30,
                Publish=True,
            )
            return result
        except botocore.exceptions.ClientError as e:
            if (
                created
                and retries < 60
                and e.response["Error"]["Code"] == "InvalidParameterValueException"
            ):
                time.sleep(1)
            else:
                raise e