5. Choose Author from scratch, and then configure the following options:
For Name, enter a name for your function.
For Runtime, choose one of the Python options.
For Role, choose Choose an existing role.
For Existing role, select the IAM role that allows the sagemaker:CreateNotebookInstance action. This is the role that you created in step 1.
6. Choose Create function.
7. In the Function code section, paste code similar to the following:
8. Scroll down to the Environment variables section, and then choose Edit.
9. Choose Add environment variable, and then create three environment variables with the following options. Environment variables allow you to store configuration settings without changing the function code.
For Key, enter ROLE.
For Value, enter the Amazon Resource Name (ARN) for the Amazon SageMaker execution role. This is the role that you created in step 2.
Note: If the Lambda function test times out, open the Lambda function again. Scroll down to the Basic settings section, and then increase the timeout value. The default is three seconds.
After you confirm that the function works, you can create a trigger to automatically run the function based on an event in another AWS service. For more information, see Using AWS Lambda with other services.