Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Pengaturan Peran IAM
Prasyarat
Sebelum Anda mulai, pastikan Anda memiliki:
AWS Akun dengan akses administratif IAM
AWS CLI diinstal dan dikonfigurasi. Untuk informasi selengkapnya, lihat Menginstal AWS CLI.
Atur variabel berikut untuk digunakan dalam perintah berikutnya:
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) REGION=$(aws configure get region)
Langkah 1: Buat peran IAM
Server SMUS MCP menggunakan peran IAM Anda untuk mengotorisasi operasi di tingkat layanan. AWS Tidak diperlukan MCP-specific izin terpisah.
Untuk membuat peran IAM (AWS CLI)
-
Buat dokumen kebijakan kepercayaan yang memungkinkan akun Anda untuk mengambil peran:
cat > mcp-trust-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAccountToAssumeRole", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::${ACCOUNT_ID}:root" }, "Action": "sts:AssumeRole" } ] } EOF -
Buat peran:
aws iam create-role \ --role-name SparkTroubleshootingMCPRole \ --assume-role-policy-document file://mcp-trust-policy.json
Langkah 2: Lampirkan izin untuk mode penerapan Anda
Lampirkan kebijakan izin yang cocok dengan platform penerapan Spark Anda. Anda dapat melampirkan satu atau beberapa hal berikut tergantung pada platform mana yang Anda gunakan.
Opsi A: EMR pada EC2
-
Buat dokumen kebijakan:
cat > emr-ec2-policy.json << 'EOF' { "Version": "2012-10-17", "Statement": [ { "Sid": "EMREC2ReadAccess", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:DescribeStep", "elasticmapreduce:ListSteps", "elasticmapreduce:ListClusters", "elasticmapreduce:DescribeJobFlows" ], "Resource": ["*"] }, { "Sid": "EMRS3LogAccess", "Effect": "Allow", "Action": ["s3:GetObject", "s3:ListBucket"], "Resource": "*" }, { "Sid": "EMRPersistentApp", "Effect": "Allow", "Action": [ "elasticmapreduce:CreatePersistentAppUI", "elasticmapreduce:DescribePersistentAppUI", "elasticmapreduce:GetPersistentAppUIPresignedURL" ], "Resource": ["*"] } ] } EOF -
Buat dan lampirkan kebijakan:
aws iam put-role-policy \ --role-name SparkTroubleshootingMCPRole \ --policy-name EMREC2TroubleshootingAccess \ --policy-document file://emr-ec2-policy.json
Atau, Anda dapat melampirkan kebijakan AmazonElasticMapReduceFullAccess AWS terkelola jika peran Anda sudah menggunakannya:
aws iam attach-role-policy \ --role-name SparkTroubleshootingMCPRole \ --policy-arn arn:aws:iam::aws:policy/AmazonElasticMapReduceFullAccess
Opsi B: AWS Glue
-
Buat dokumen kebijakan:
cat > glue-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Sid": "GlueReadAccess", "Effect": "Allow", "Action": [ "glue:GetJob", "glue:GetJobRun", "glue:GetJobRuns", "glue:GetJobs", "glue:BatchGetJobs" ], "Resource": ["arn:aws:glue:*:${ACCOUNT_ID}:job/*"] }, { "Sid": "GlueCloudWatchLogsAccess", "Effect": "Allow", "Action": ["logs:GetLogEvents", "logs:FilterLogEvents"], "Resource": ["arn:aws:logs:*:${ACCOUNT_ID}:log-group:/aws/glue/*"] }, { "Sid": "GlueSparkWebUI", "Effect": "Allow", "Action": [ "glue:RequestLogParsing", "glue:GetLogParsingStatus", "glue:GetEnvironment", "glue:GetStage", "glue:GetStages", "glue:GetStageFiles", "glue:BatchGetStageFiles", "glue:GetStageAttempt", "glue:GetStageAttemptTaskList", "glue:GetStageAttemptTaskSummary", "glue:GetExecutors", "glue:GetExecutorsThreads", "glue:GetStorage", "glue:GetStorageUnit", "glue:GetQueries", "glue:GetQuery", "glue:GetDashboardUrl" ], "Resource": ["arn:aws:glue:*:${ACCOUNT_ID}:job/*"] }, { "Sid": "GluePassRoleAccess", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*", "Condition": { "StringLike": { "iam:PassedToService": "glue.amazonaws.com" } } } ] } EOF -
Lampirkan kebijakan:
aws iam put-role-policy \ --role-name SparkTroubleshootingMCPRole \ --policy-name GlueTroubleshootingAccess \ --policy-document file://glue-policy.json
Opsi C: EMR Tanpa Server
-
Buat dokumen kebijakan:
cat > emr-serverless-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Sid": "EMRServerlessReadAccess", "Effect": "Allow", "Action": [ "emr-serverless:GetJobRun", "emr-serverless:GetApplication", "emr-serverless:ListApplications", "emr-serverless:ListJobRuns", "emr-serverless:ListJobRunAttempts", "emr-serverless:GetDashboardForJobRun", "emr-serverless:ListTagsForResource" ], "Resource": ["*"] }, { "Sid": "EMRServerlessCloudWatchLogsAccess", "Effect": "Allow", "Action": ["logs:GetLogEvents", "logs:FilterLogEvents"], "Resource": ["arn:aws:logs:*:${ACCOUNT_ID}:log-group:/aws/emr-serverless/*"] }, { "Sid": "EMRServerlessS3LogsAccess", "Effect": "Allow", "Action": ["s3:GetObject", "s3:ListBucket"], "Resource": "*" } ] } EOF -
Lampirkan kebijakan:
aws iam put-role-policy \ --role-name SparkTroubleshootingMCPRole \ --policy-name EMRServerlessTroubleshootingAccess \ --policy-document file://emr-serverless-policy.json
Opsional: Izin KMS untuk Log terenkripsi CloudWatch
Jika CloudWatch Log Anda dienkripsi dengan kunci KMS yang dikelola pelanggan, tambahkan yang berikut ini (ganti <KEY_ID> dengan ID kunci KMS Anda):
aws iam put-role-policy \ --role-name SparkTroubleshootingMCPRole \ --policy-name KMSCloudWatchLogsDecrypt \ --policy-document "{ \"Version\": \"2012-10-17\", \"Statement\": [{ \"Effect\": \"Allow\", \"Action\": [\"kms:Decrypt\", \"kms:DescribeKey\"], \"Resource\": \"arn:aws:kms:${REGION}:${ACCOUNT_ID}:key/<KEY_ID>\" }] }"
Langkah 3: Konfigurasikan klien MCP Anda
Konfigurasikan klien MCP Anda (misalnya, Claude Desktop atau Amazon Q Developer) untuk menggunakan peran ARN yang Anda buat:
echo "arn:aws:iam::${ACCOUNT_ID}:role/SparkTroubleshootingMCPRole"
Lihat dokumentasi klien MCP Anda untuk mengetahui cara mengonfigurasi AWS kredensil (biasanya melalui AWS profil yang mengasumsikan peran ini).
Kunci kondisi untuk permintaan server MCP
Dua tombol kondisi secara otomatis ditambahkan ke semua permintaan yang dibuat melalui server SMUS MCP:
aws:ViaAWSMCPService— Setel ketrueuntuk setiap permintaan yang dibuat melalui server MCP AWS terkelola.aws:CalledViaAWSMCP— Setel ke prinsipal layanan server MCP (misalnya,sagemaker-unified-studio-mcp.amazonaws.com).
Anda dapat menggunakan tombol kondisi ini untuk mengontrol akses ke sumber daya Anda saat permintaan berasal dari server MCP AWS terkelola.
Contoh: Izinkan operasi baca Glue hanya ketika diakses melalui server SMUS MCP:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowGlueReadViaSMUSMCP", "Effect": "Allow", "Action": ["glue:GetJob", "glue:GetJobRun", "glue:GetJobRuns"], "Resource": "*", "Condition": { "StringEquals": { "aws:CalledViaAWSMCP": "sagemaker-unified-studio-mcp.amazonaws.com" } } } ] }
Contoh: Tolak operasi penghapusan saat diakses melalui server MCP AWS terkelola:
{ "Effect": "Deny", "Action": ["s3:DeleteObject", "s3:DeleteBucket"], "Resource": "*", "Condition": { "Bool": { "aws:ViaAWSMCPService": "true" } } }
Untuk informasi selengkapnya tentang kunci kondisi, lihat kunci konteks kondisi AWS global di Panduan Pengguna IAM.