<jupyter_start><jupyter_text>Generating a synthetic dataset and using the SageMaker Feature Store for storage and management This notebook contains the code to help readers work through one of the recipes of the book [Machine Learning with Amazon SageMaker Cookbook: 80 proven recipes for data scientists and developers to perform ML experiments and deployments](https://www.amazon.com/Machine-Learning-Amazon-SageMaker-Cookbook/dp/1800567030)  How to do it...<jupyter_code>%load https://raw.githubusercontent.com/PacktPublishing/Amazon-SageMaker-Cookbook/master/Chapter07/scripts/generator.py
all_df
import boto3
import sagemaker
from sagemaker.session import Session
region = boto3.Session().region_name
session = boto3.Session(region_name=region)

client = session.client(
    service_name='sagemaker', 
    region_name=region
)

runtime = session.client(
    service_name='sagemaker-featurestore-runtime', 
    region_name=region
)

feature_store_session = Session(
    boto_session=session,
    sagemaker_client=client,
    sagemaker_featurestore_runtime_client=runtime
)
s3_bucket_name = "<insert S3 bucket name here>"
prefix = "chapter07"

from sagemaker import get_execution_role
role = get_execution_role()
s3_client = boto3.client('s3', region_name=region)
feature_group_name = 'cookbook-feature-group'
from sagemaker.feature_store.feature_group import FeatureGroup

feature_group = FeatureGroup(
    name=feature_group_name, 
    sagemaker_session=feature_store_session
)
try:
    feature_group.delete()
    sleep(30)
except:
    print("Feature group does not exist")
    pass
%%time

feature_group.load_feature_definitions(data_frame=all_df)
sleep(1)
feature_group.create(
    s3_uri=f"s3://{s3_bucket_name}/{prefix}/input",
    record_identifier_name="index",
    event_time_feature_name="event_time",
    role_arn=role,
    enable_online_store=True
)

sleep(60)
feature_group.describe()
feature_group.describe().get("FeatureGroupStatus")
client.list_feature_groups()
all_df.dtypes
%%time

feature_group.ingest(
    data_frame=all_df, max_workers=3, wait=True
)
runtime.get_record(
    FeatureGroupName=feature_group.name, 
    RecordIdentifierValueAsString="300"
)
%store feature_group_name
%store s3_bucket_name
%store prefix<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08854625550660793, 'fraction_numerical': 0.01629955947136564, 'mean_word_length': 6.16403785488959, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '217414', 'license': 'MIT', 'n_tokens_mistral': 748, 'n_tokens_neox': 713, 'n_words': 147, 'path': 'Chapter07/01 - Generating a synthetic dataset and using the SageMaker Feature Store for storage and management.ipynb', 'repo_name': 'MARKOM/sagemaker-cookbook', 'size': '2270'}