Skip to main content

SageMakerStudioDataEngineeringSessions

SageMaker Unified Studio Data Engineering Sessions

This pacakge depends on SageMaker Unified Studio environment, if you are using SageMaker Unified Studio, see AWS Doc for guidance.

This package contains functionality to support SageMaker Unified Studio connecting to various AWS Compute including EMR/EMR Serverless/Glue/Redshift etc.

It is utilizing ipython magics and AWS DataZone Connections to achieve the following features.

Features

  • Connect to remote compute
  • Execute Spark code in remote compute in Python/Scala
  • Execute SQL queries in remote compute
  • Send local variables to remote compute

How to setup

If you are using SageMaker Unifed Studio, you can skip this part, SageMaker Unifed Studio already set up the package.

This package contains various Jupyter Magics to achieve its functionality.

To load these magics, make sure you have iPython config file generated. If not, you could run ipython profile create, then a file with path ~/.ipython/profile_default/ipython_config.py should be generated

Then you will need to add the following line in the end of that config file

c.InteractiveShellApp.extensions.extend(['sagemaker_studio_dataengineering_sessions.sagemaker_connection_magic'])

Once that is finished, you could restart the ipython kernel and run %help to see a list of supported magics

Interactive vs background session

This packages uses SM_INPUT_NOTEBOOK_NAME environment variable to determine if the execution is through interactive or background session. See sagemaker_studio_dataengineering_sessions/sagemaker_database_session_manager/redshift/redshift_session.py file for usage.

Examples

To connect to remote compute, a DataZone Connection is required, you could create it via CreateConnection API, Let's say there's an existing connection called project.spark.

Supported Connection Type:

  • IAM
  • SPARK
  • REDSHIFT
  • ATHENA

Connect to remote compute and Execute Spark Code in Python

The following example will connect to AWS Glue Interactive session and run the spark code in Glue.

%%pyspark project.spark

import sys
import boto3
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from pyspark.sql import SparkSession
from pyspark.sql.functions import col

args = getResolvedOptions(sys.argv, ["redshift_url", "redshift_iam_role", "redshift_tempdir","redshift_jdbc_iam_url"])
print(f"{args}")

sc = SparkContext.getOrCreate()
spark = SparkSession(sc)

df = spark.read.csv(f"s3://sagemaker-example-files-prod-{boto3.session.Session().region_name}/datasets/tabular/dirty-titanic/", header=True)
df.show(5, truncate=False)
df.printSchema()

df.createOrReplaceTempView("df_sql_tempview")

Execute Spark Code in Scala

The following example will connect to AWS Glue Interactive session and run the spark code in Scala.

%%scalaspark project.spark
val dfScala = spark.sql("SELECT count(0) FROM df_sql_tempview")
dfScala.show()

Execute SQL query in remote compute

The following example will connect to AWS Glue Interactive session and run the spark code in Scala.

%%sql project.redshift
select current_user()

Some other helpful magics

%help - list available magics and related information

%send_to_remote - send local variable to remote compute

%%configure - configure spark application config in remote compute

Metadata

Release files for sagemaker-studio-dataengineering-sessions 1.3.28

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sagemaker-studio-dataengineering-sessions 1.3.28
File Size Uploaded Provenance Actions
sagemaker_studio_dataengineering_sessions-1.3.28.tar.gz 276.8 kB Without provenance Details for sagemaker_studio_dataengineering_sessions-1.3.28.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sagemaker-studio-dataengineering-sessions 1.3.28
File Interpreter ABI Platform Actions
sagemaker_studio_dataengineering_sessions-1.3.28-py3-none-any.whl Python 3 none any Details for sagemaker_studio_dataengineering_sessions-1.3.28-py3-none-any.whl

Total release size: 617.8 kB

Release files / sagemaker_studio_dataengineering_sessions-1.3.28.tar.gz

Download URL sagemaker_studio_dataengineering_sessions-1.3.28.tar.gz
Size 276.8 kB
Tags Source
SHA-256 checksum
How to use checksums
15eb48bf706cd9a6a1f02ce9850fff2332f67dfce8e652175a24b4867fe7ce8d
BLAKE2b-256 checksum
How to use checksums
8ce9ae52460a4e17986ff4064c718ac6d4334468853aae289212dfa66ecc0eb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / sagemaker_studio_dataengineering_sessions-1.3.28-py3-none-any.whl

Download URL sagemaker_studio_dataengineering_sessions-1.3.28-py3-none-any.whl
Size 341.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8ae616f23b3cc6c446d990c1bb0885e49868741c53475b71ea57553b26e3bf8
BLAKE2b-256 checksum
How to use checksums
ad69dd491f97720a9e93ed666814d1a2b97ce70f06f6761c5ed951dd9f3dfc69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for sagemaker-studio-dataengineering-sessions 1.3.28

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.28 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page