hf-cloud-sagemaker-iam-preflight

작성자: huggingface

SageMaker 실행 역할이 배포 또는 학습 전에 사용 가능한 상태인지 확인합니다. SageMaker 엔드포인트, 모델, 학습 등을 생성하기 전에 이 스킬을 사용하십시오.

npx skills add https://github.com/huggingface/skills --skill hf-cloud-sagemaker-iam-preflight

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-identity fails inside Bash even when it works natively in PowerShell. (This is exactly why the old .sh helpers failed on Windows and were replaced with Python.) If you're in PowerShell, run python ...\check_role.py directly 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 where aws sts get-caller-identity returns 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.py

Lists 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:AttachRolePolicy, 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 — see references/trust-policy.json for the canonical form.

check_role.py verifies these two. It does not deep-check permissions because comprehensive analysis is expensive (iam:SimulatePrincipalPolicy per action) and most existing SageMaker roles are over-permissioned via AmazonSageMakerFullAccess. If you suspect a permissions issue at deploy time, the deployment error will tell you which action was denied — fix it then, not preemptively.

Minimum permissions

references/minimum-permissions.json covers what SageMaker actually needs:

  • s3:GetObject + s3:ListBucket on the model artifact bucket
  • ECR pull permissions
  • CloudWatch logs and metrics

Layered on top of AmazonSageMakerFullAccess (attached by create_role.py). 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.

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 text

Pick 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.

huggingface의 다른 스킬

cpu-kernels
huggingface
C++ CPU 커널을 SIMD 내장 함수(AVX2/AVX512)로 작성, 최적화 및 벤치마킹하는 방법에 대한 지침을 제공하며, Hugging Face 커널 생태계를 대상으로 합니다. 포함 사항…
official
generate-openenv-env
huggingface
구체적인 사용 사례(예: "라이브러리 textarena를 위한 환경 생성")로부터 OpenEnv 환경을 생성합니다. 새로운 환경을 설계하거나 구현하라는 요청을 받았을 때 사용하세요.
official
hf-mcp
huggingface
Hugging Face Hub를 MCP 서버 도구를 통해 사용하세요. 모델, 데이터셋, 스페이스, 논문을 검색하고, 저장소 세부 정보를 확인하며, 문서를 가져오고, 컴퓨팅 작업을 실행하고, Gradio를 사용할 수 있습니다…
official
trl-training
huggingface
트랜스포머 언어 모델을 TRL(Transformers Reinforcement Learning)을 사용하여 학습 및 미세 조정합니다. SFT, DPO, GRPO, KTO, RLOO 및 보상 모델 학습을 지원합니다…
official
deploy-hf
huggingface
OpenEnv 환경을 Hugging Face Spaces에 배포합니다. 배포, Hugging Face로 푸시, 또는 스페이스 업데이트를 요청받았을 때 사용하세요.
official
hf-space-recovery
huggingface
Diagnose and recover failing or stuck Hugging Face Space deployments for OpenEnv environments. Use when deploying envs from `envs/` to the Hub (`openenv`…
official
pre-submit-pr
huggingface
풀 리퀘스트를 제출하기 전에 변경 사항을 검증합니다. 린트, 테스트, 정렬 검토 및 RFC 분석을 포함한 포괄적인 검사를 실행합니다. 생성하기 전에 사용합니다…
official
example-skill
huggingface
액션 스모크 테스트용 예제 픽스처 스킬
official