AWS Command Line Interface v2를 사용하여 DynamoDB 리소스 기반 정책 관리
다음 코드 예제에서는 DynamoDB 테이블에 대한 리소스 기반 정책의 전체 수명 주기를 관리하는 방법을 보여줍니다.
리소스 정책을 포함한 테이블을 생성합니다.
리소스 정책을 가져옵니다.
리소스 정책을 업데이트합니다.
리소스 정책을 삭제합니다.
- Bash
-
- Bash 스크립트와 함께 AWS CLI사용
-
리소스 정책을 포함한 테이블을 생성합니다.
# Step 1: Create a DynamoDB table aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST # Step 2: Create a resource-based policy document cat > policy.json << 'EOF' { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/DynamoDBReadOnly" }, "Action": [ "dynamodb:GetItem", "dynamodb:BatchGetItem", "dynamodb:Query", "dynamodb:Scan" ], "Resource": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection" } ] } EOF # Step 3: Attach the resource-based policy to the table aws dynamodb put-resource-policy \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --policy file://policy.json
리소스 정책을 가져옵니다.
# Get the resource-based policy attached to a table aws dynamodb get-resource-policy \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection
리소스 정책을 업데이트합니다.
# Step 1: Create an updated policy document cat > updated-policy.json << 'EOF' { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "arn:aws:iam::123456789012:role/DynamoDBReadOnly", "arn:aws:iam::123456789012:role/DynamoDBAnalytics" ] }, "Action": [ "dynamodb:GetItem", "dynamodb:BatchGetItem", "dynamodb:Query", "dynamodb:Scan" ], "Resource": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection" } ] } EOF # Step 2: Update the resource-based policy on the table aws dynamodb put-resource-policy \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --policy file://updated-policy.json
리소스 정책을 삭제합니다.
# Delete the resource-based policy from a table aws dynamodb delete-resource-policy \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection
-
API 세부 정보는 AWS CLI 명령 참조의 다음 토픽을 참조하세요.
-
AWS SDK 개발자 가이드 및 코드 예시의 전체 목록은 AWS SDK와 함께 DynamoDB 사용 섹션을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.
글로벌 보조 인덱스 관리
DynamoDB 성능 모니터링