Skip to content

Commit b14f2b6

Browse files
committed
Adding information about creating an IAM role using the CLI
1 parent d1a5af0 commit b14f2b6

File tree

1 file changed

+98
-2
lines changed
  • src/connections/storage/catalog/aws-s3

1 file changed

+98
-2
lines changed

src/connections/storage/catalog/aws-s3/index.md

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ The Segment Tracking API processes data from your sources, and collects the Even
3434

3535
## Create a new destination
3636

37-
Complete the following steps to configure the AWS S3 Destination with IAM Role Support.
37+
Complete either [Create an IAM role in the AWS console](#create-an-iam-role-in-the-aws-console) or [Create an IAM role using the AWS CLI](#create-an-aws-role-using-the-aws-cli) to configure the AWS S3 Destination with IAM Role Support.
3838

39-
### Create an IAM role in AWS
39+
### Create an IAM role in the AWS console
4040

4141
To complete this section, you need access to your AWS dashboard.
4242

@@ -100,6 +100,102 @@ To complete this section, you need access to your AWS dashboard.
100100

101101
If you have server-side encryption enabled, see the [required configuration](#encryption).
102102

103+
### Create an IAM role using the AWS CLI
104+
105+
To create an IAM role with external ID and with S3 permissions using the AWS CLI, follow the steps below.
106+
107+
#### Prerequisites
108+
To create an S3 IAM role, you must first install and configure the AWS CLI on your local machine and create an S3 bucket. Refer to Amazon's documentation, [Getting started with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) for more information.
109+
110+
#### Procedure
111+
1. Copy the following code snippet and save it as a file on your local machine titled `trust-relationship-policy.json`. Replace `<YOUR_WORKSPACE_ID>` with your Segment workspace ID.
112+
113+
```json
114+
115+
{
116+
"Version": "2012-10-17",
117+
"Statement": [
118+
{
119+
"Sid": "",
120+
"Effect": "Allow",
121+
"Principal": {
122+
"AWS": "arn:aws:iam::595280932656:role/segment-s3-integration-production-access"
123+
},
124+
"Action": "sts:AssumeRole",
125+
"Condition": {
126+
"StringEquals": {
127+
"sts:ExternalId": "<YOUR_WORKSPACE_ID>"
128+
}
129+
}
130+
}
131+
]
132+
}
133+
```
134+
135+
2. Navigate to the folder containing `trust-relationship-policy.json` and run the following command to create your IAM role and attach the trust relationship document, replacing `<YOUR_ROLE_NAME>` with the name you want to give this IAM role:
136+
137+
``` python
138+
aws iam create-role --role-name <YOUR_ROLE_NAME> --assume-role-policy-document file://trust-relationship-policy.json --description "IAM role for Segment to assume (AWS S3 destination)"
139+
```
140+
141+
>info ""
142+
> To verify that you successfully created an IAM role, log into your AWS console and open the IAM Management Console. Under the Trust Relationship tab, there should be a key-value pair: a `sts:ExternalID` key with a value of `your Segment workspace ID`.
143+
144+
3. Copy the following IAM policy, replacing `<YOUR_BUCKET_NAME>` with the name of your S3 bucket, and save it as a file on your local machine titled `iam-policy.json`.
145+
146+
```json
147+
148+
{
149+
"Version": "2012-10-17",
150+
"Statement": [
151+
{
152+
"Sid": "PutObjectsInBucket",
153+
"Effect": "Allow",
154+
"Action": [
155+
"s3:PutObject",
156+
"s3:PutObjectAcl"
157+
],
158+
"Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/segment-logs/*"
159+
}
160+
]
161+
}
162+
163+
```
164+
165+
5. Navigate to the folder containing `iam-policy.json`, and run the following command to create the IAM policy:
166+
167+
``` python
168+
aws iam create-policy --policy-name segment-s3-putobject --policy-document file://iam-policy.json --description "Allow Segment to PutObject into S3 destination bucket"
169+
```
170+
6. A successful output has the following format. Take note of the `Arn,` as you'll need it in the next step.
171+
172+
``` json
173+
174+
{
175+
"Policy": {
176+
"PolicyName": "segment-s3-putobject",
177+
"PolicyId": "AABC1DE2F34GG567H",
178+
"Arn": "arn:aws:iam::012345678912:policy/segment-s3-putobject",
179+
"Path": "/",
180+
"DefaultVersionId": "v1",
181+
"AttachmentCount": 0,
182+
"PermissionsBoundaryUsageCount": 0,
183+
"IsAttachable": true,
184+
"CreateDate": "2021-11-11T01:21:00+00:00",
185+
"UpdateDate": "2021-11-11T01:21:00+00:00"
186+
}
187+
}
188+
189+
```
190+
7. Run the following command to attach the IAM policy to the IAM role, replacing `<YOUR_ROLE_NAME>` with the name of your role and `<ARN_FROM_STEP_6_OUTPUT>` with the Arn output from the last step:
191+
192+
``` python
193+
aws iam attach-role-policy --role-name <YOUR_ROLE_NAME> --policy-arn <ARN_FROM_STEP_6_OUTPUT>
194+
```
195+
196+
> info ""
197+
> To verify that you have successfully created your IAM role, navigate to your AWS console and open the IAM Management Console. On the Permissions tab, verify that there is a `segment-s3-putobject` Permissions policy.
198+
103199

104200
### Add the AWS S3 with IAM Role Support Destination
105201

0 commit comments

Comments
 (0)