|
| 1 | +--- |
| 2 | +title: "Access your own AWS S3 bucket in Databend Cloud with IAM Role" |
| 3 | +--- |
| 4 | + |
| 5 | +# Why IAM Role |
| 6 | + |
| 7 | +With AWS IAM Role, you can access your own AWS S3 buckets in Databend Cloud. This allows you to securely access your data and perform data analysis without having to manage your AWS credentials. |
| 8 | + |
| 9 | +# How to Use IAM Role |
| 10 | + |
| 11 | +1. Raise a support ticket to get the IAM role ARN for your Databend Cloud organization: |
| 12 | + |
| 13 | + For example: `arn:aws:iam::123456789012:role/xxxxxxx/tnabcdefg/xxxxxxx-tnabcdefg` |
| 14 | + |
| 15 | +2. Goto AWS Console: |
| 16 | + |
| 17 | + https://us-east-2.console.aws.amazon.com/iam/home?region=us-east-2#/policies |
| 18 | + |
| 19 | + Click `Create policy`, and select `Custom trust policy`, and input the policy document for S3 bucket access: |
| 20 | + |
| 21 | + ```json |
| 22 | + { |
| 23 | + "Version": "2012-10-17", |
| 24 | + "Statement": [ |
| 25 | + { |
| 26 | + "Effect": "Allow", |
| 27 | + "Action": "s3:ListBucket", |
| 28 | + "Resource": "arn:aws:s3:::test-bucket-123" |
| 29 | + }, |
| 30 | + { |
| 31 | + "Effect": "Allow", |
| 32 | + "Action": "s3:*Object", |
| 33 | + "Resource": "arn:aws:s3:::test-bucket-123/*" |
| 34 | + } |
| 35 | + ] |
| 36 | + } |
| 37 | + ``` |
| 38 | + |
| 39 | + Click `Next`, and input the policy name: `databend-test`, and click `Create policy` |
| 40 | + |
| 41 | +3. Goto AWS Console: |
| 42 | + |
| 43 | + https://us-east-2.console.aws.amazon.com/iam/home?region=us-east-2#/roles |
| 44 | + |
| 45 | + Click `Create role`, and select `Custom trust policy` in `Trusted entity type`: |
| 46 | + |
| 47 | +  |
| 48 | + |
| 49 | + Input the the trust policy document: |
| 50 | + |
| 51 | + ```json |
| 52 | + { |
| 53 | + "Version": "2012-10-17", |
| 54 | + "Statement": [ |
| 55 | + { |
| 56 | + "Effect": "Allow", |
| 57 | + "Principal": { |
| 58 | + "AWS": "arn:aws:iam::123456789012:role/xxxxxxx/tnabcdefg/xxxxxxx-tnabcdefg" |
| 59 | + }, |
| 60 | + "Action": "sts:AssumeRole" |
| 61 | + } |
| 62 | + ] |
| 63 | + } |
| 64 | + ``` |
| 65 | + |
| 66 | + Click `Next`, and select the previously created policy: `databend-test` |
| 67 | + |
| 68 | + Click `Next`, and input the role name: `databend-test` |
| 69 | + |
| 70 | + Click `View Role`, and record the role ARN: `arn:aws:iam::987654321987:role/databend-test` |
| 71 | + |
| 72 | +4. Run the following SQL statement in Databend Cloud cloud worksheet or `BendSQL`: |
| 73 | + |
| 74 | + ```sql |
| 75 | + CREATE CONNECTION databend_test STORAGE_TYPE = 's3' ROLE_ARN = 'arn:aws:iam::987654321987:role/databend-test'; |
| 76 | + |
| 77 | + CREATE STAGE databend_test URL = 's3://test-bucket-123' CONNECTION = (CONNECTION_NAME = 'databend_test'); |
| 78 | + |
| 79 | + SELECT * FROM @databend_test/test.parquet LIMIT 1; |
| 80 | + ``` |
| 81 | + |
| 82 | +:::info |
| 83 | +Congratulations! You could now access your own AWS S3 buckets in Databend Cloud with IAM Role. |
| 84 | +::: |
0 commit comments