Hf Cloud Sagemaker Iam Preflight
Hugging FaceOfficialPublished by Hugging Face
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a set of Python-based helpers to manage AWS SageMaker execution roles. It is designed to prevent common deployment failures by verifying that a valid IAM role exists before attempting to create resources like endpoints, models, or training jobs. The skill follows a strict order of operations: it first validates a user-provided role, then attempts to discover existing roles based on usage and creation date, and only suggests role creation if no suitable role is found. It specifically addresses issues encountered by SSO principals who may lack the necessary IAM permissions to create roles.
What it does
- Validates specific IAM role ARNs provided by the user.
- Discovers existing SageMaker execution roles by ranking them based on last-used date and creation date.
- Verifies that a role's trust policy allows SageMaker to assume the role.
- Provides a mechanism to create new roles with scoped S3 access when no suitable role is found.
- Offers guidance on applying minimum required permissions instead of broad managed policies.
- Provides native AWS CLI fallback commands for manual verification.
When to use it
- Before deploying SageMaker endpoints, models, or training jobs.
- When a deployment script fails due to missing IAM permissions or an invalid execution role.
- When working as an SSO principal that lacks broad IAM creation privileges.
- When you need to ensure an existing role is correctly configured for SageMaker operations.
Advantages
- Prevents common AccessDenied errors during SageMaker resource creation.
- Promotes the use of existing, actively maintained roles over creating new ones.
- Enforces the principle of least privilege by using scoped inline policies.
- Provides clear error messaging when the user lacks sufficient permissions to create roles.
Usage examples
- “Check if there is a usable SageMaker execution role available in my current AWS environment.”
- The agent runs the discovery script to identify and return the most recently used or newest valid SageMaker execution role.
- “I need to create a new SageMaker role for my model bucket named my-model-data.”
- The agent executes the creation script to generate a role with the necessary trust policy and scoped S3 access to the specified bucket.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/huggingface/hf-cloud-sagemaker-iam-preflight/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip hf-cloud-sagemaker-iam-preflight.zip -d .agents/skills
Documentation by Hugging Face
SageMaker IAM Preflight
Every SageMaker resource needs an execution role — the IAM role SageMaker assumes to read model artifacts from S3, pull serving containers from ECR, and write logs. Most deployments fail here because the script tried to create a new role without checking if a usable one already existed, then blew up because the caller is an SSO principal.
This skill encodes the right order: discover, validate, only create if necessary.
Running the helpers (cross-platform)
The helpers are Python so they run identically on Windows, macOS, and Linux:
python3 scripts/check_role.py # macOS / Linux
python scripts/check_role.py # Windows (PowerShell / cmd)Run them from the shell where the AWS CLI already works — i.e. wherever aws sts get-caller-identity succeeds. The script shells out to that same aws binary and inherits the shell's profile, region, SSO session, proxy, and credential chain.
Windows / WSL / Git Bash caveat. Do not invoke these through a Bash shim (WSL, Git Bash, MSYS) on Windows. Those Bash environments frequently do not share the Windows AWS config, credentials, SSO sessions, environment variables, or proxy settings — so
aws sts get-caller-identityfails inside Bash even when it works natively in PowerShell. (This is exactly why the old.shhelpers failed on Windows and were replaced with Python.) If you're in PowerShell, runpython ...\check_role.pydirectly in PowerShell. If the helper still can't see your identity, run the same discovery natively (see "Native AWS CLI equivalent" below) in the shell whereaws sts get-caller-identityreturns your ARN.
Order of operations
Step 1 — Did the user provide a role?
Validate that one specifically:
python3 scripts/check_role.py "<role-name-or-arn>"On success it prints the ARN to stdout (exit 0). On failure it logs why on stderr. Don't try to silently fix a broken role — surface the problem.
Step 2 — Discover existing roles
python3 scripts/check_role.pyLists roles matching common SageMaker patterns (AmazonSageMaker-ExecutionRole-*, SageMakerExecutionRole*, etc.), ranks by last-used date (most recent first), validates trust policy in that order, returns the first usable ARN. Most accounts that have used SageMaker before already have one.
Why rank by last-used: in accounts with multiple roles (auto-generated 2021 role + manual project role + etc.), the alphabetically-first one is rarely the actively-maintained one. The most-recently-used role is more likely to have current policies — including cross-account ECR pull. The script prints the ranking so you can see which got picked.
IAM frequently reports no RoleLastUsed at all (tracking only covers recent activity). When every candidate ties at "never used", the script falls back to newest creation date — a newer role is more likely to have current policies than a 2021 leftover.
Step 3 — Create, only if discovery found nothing
If the user can create (has IAM permissions):
python3 scripts/create_role.py "<role-name>" "<model-bucket>"Second arg scopes S3 access to a specific bucket. Omit if unknown; script warns and the user can update the policy later.
If the user cannot create (SSO principal — hf-cloud-aws-context-discovery will have flagged this):
Stop and surface this clearly. Don't retry alternative IAM operations hoping one works:
I can't find an existing SageMaker execution role, and you're authenticated via SSO so you can't create one directly. Please either:
Ask your AWS admin for a SageMaker execution role ARN, or
Have them grant your SSO permission set
iam:CreateRole,iam:PutRolePolicy
Specific instructions get unblocked fast; vague "permission denied" messages don't.
What "validated" means
A role is usable when (1) it exists, (2) its trust policy allows sagemaker.amazonaws.com to sts:AssumeRole, and (3) its permissions grant only the actions and resources this deployment needs. See references/trust-policy.json for the canonical trust policy.
check_role.py verifies existence and trust because policy evaluation depends on the deployment's exact S3, ECR, logging, and optional output resources. Before deployment, inspect the selected role's policies and compare them with references/minimum-permissions.json; add only missing actions and scope them to the required resources. Do not attach AmazonSageMakerFullAccess or defer permission review until an AccessDenied failure.
Minimum permissions
references/minimum-permissions.json is the standalone inline policy for endpoint execution:
s3:GetObject+s3:ListBucketon the model artifact bucketECR pull permissions
CloudWatch logs and metrics
create_role.py installs this inline policy without attaching a managed FullAccess policy. Replace REPLACE_WITH_MODEL_BUCKET in the template with the actual bucket name — create_role.py does this automatically when given a bucket as its second argument. Add narrowly scoped permissions separately for optional features such as async output or data capture.
Native AWS CLI equivalent (fallback)
If the Python helper can't run or can't see your identity (rare — usually a broken PATH or running under a Bash shim that lacks AWS context), do the same preflight by hand in the shell where aws sts get-caller-identity works. The logic is just AWS CLI calls; the helper exists only to bundle and rank them.
PowerShell:
# 1. List candidate SageMaker roles
aws iam list-roles --query "Roles[?contains(RoleName,'SageMaker') || contains(RoleName,'sagemaker')]" --output json
# 2. For each candidate, confirm the trust policy allows sagemaker.amazonaws.com
aws iam get-role --role-name <role-name> --query "Role.AssumeRolePolicyDocument" --output json
# 3. Prefer the most-recently-used role with SageMaker-execution naming
# (LastUsedDate is often None for every role — then prefer newest CreateDate)
aws iam get-role --role-name <role-name> --query "Role.[RoleLastUsed.LastUsedDate, CreateDate]" --output textPick the most-recently-used role whose trust policy contains sagemaker.amazonaws.com. Use the resulting ARN exactly as if check_role.py had returned it. Bash/macOS/Linux use the same commands.
Files
- ATTRIBUTION.mdAdded by AutoGineer908 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md6.9 KiB
- references/minimum-permissions.json1.0 KiB
- references/trust-policy.json197 B
- scripts/check_role.pyScript6.7 KiB
- scripts/create_role.pyScript3.8 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs a command-line tool, Needs Python
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Hugging Face
- Publisher
- Hugging Face (Official)
- Source
- huggingface/skills · skills/hf-cloud-sagemaker-iam-preflight · commit 25910b3
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Hugging Face.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download hf-cloud-sagemaker-iam-preflight.zip