Skip to content

Commit be4f272

Browse files
Merge pull request #2150 from segmentio/s3-role-creation
Create an IAM role using the AWS CLI
2 parents 58e0fe1 + ad0dcdd commit be4f272

File tree

1 file changed

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

1 file changed

+98
-8
lines changed

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

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ redirect_from:
55
hide-personas-partial: true
66
---
77

8-
> info "This document is about a destination which is in beta"
9-
> This means that the AWS S3 with IAM Role Support destination is in active development, and some functionality may change before it becomes generally available.
10-
118

129
## Differences between the Amazon S3 destination and the AWS S3 destination
1310

@@ -34,9 +31,9 @@ The Segment Tracking API processes data from your sources, and collects the Even
3431

3532
## Create a new destination
3633

37-
Complete the following steps to configure the AWS S3 Destination with IAM Role Support.
34+
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-iam-role-using-the-aws-cli) to configure the AWS S3 Destination with IAM Role Support.
3835

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

4138
To complete this section, you need access to your AWS dashboard.
4239

@@ -94,12 +91,105 @@ To complete this section, you need access to your AWS dashboard.
9491
],
9592
"Resource": "<YOUR_KEY_ARN>"
9693
}
97-
]
94+
]
9895
}
9996
```
10097

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

100+
### Create an IAM role using the AWS CLI
101+
102+
To create an IAM role with external ID and with S3 permissions using the AWS CLI, follow the steps below.
103+
104+
#### Prerequisites
105+
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){:target="_blank"} for more information.
106+
107+
#### Procedure
108+
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.
109+
110+
```json
111+
{
112+
"Version": "2012-10-17",
113+
"Statement": [
114+
{
115+
"Sid": "",
116+
"Effect": "Allow",
117+
"Principal": {
118+
"AWS": "arn:aws:iam::595280932656:role/segment-s3-integration-production-access"
119+
},
120+
"Action": "sts:AssumeRole",
121+
"Condition": {
122+
"StringEquals": {
123+
"sts:ExternalId": "<YOUR_WORKSPACE_ID>"
124+
}
125+
}
126+
}
127+
]
128+
}
129+
```
130+
131+
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:
132+
133+
``` python
134+
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)"
135+
```
136+
137+
3. To verify that the IAM role is created, log into the 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`.
138+
139+
4. 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`.
140+
141+
```json
142+
{
143+
"Version": "2012-10-17",
144+
"Statement": [
145+
{
146+
"Sid": "PutObjectsInBucket",
147+
"Effect": "Allow",
148+
"Action": [
149+
"s3:PutObject",
150+
"s3:PutObjectAcl"
151+
],
152+
"Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/segment-logs/*"
153+
}
154+
]
155+
}
156+
```
157+
158+
5. Navigate to the folder containing `iam-policy.json`, and run the following command to create the IAM policy:
159+
160+
``` python
161+
aws iam create-policy --policy-name segment-s3-putobject --policy-document file://iam-policy.json --description "Allow Segment to PutObject into S3 destination bucket"
162+
```
163+
164+
6. A successful output has the following format. Take note of the `Arn`, as you'll need it in the next step.
165+
166+
``` json
167+
{
168+
"Policy": {
169+
"PolicyName": "segment-s3-putobject",
170+
"PolicyId": "AABC1DE2F34GG567H",
171+
"Arn": "arn:aws:iam::012345678912:policy/segment-s3-putobject",
172+
"Path": "/",
173+
"DefaultVersionId": "v1",
174+
"AttachmentCount": 0,
175+
"PermissionsBoundaryUsageCount": 0,
176+
"IsAttachable": true,
177+
"CreateDate": "2021-11-11T01:21:00+00:00",
178+
"UpdateDate": "2021-11-11T01:21:00+00:00"
179+
}
180+
}
181+
182+
```
183+
184+
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:
185+
186+
``` python
187+
aws iam attach-role-policy --role-name <YOUR_ROLE_NAME> --policy-arn <ARN_FROM_STEP_6_OUTPUT>
188+
```
189+
190+
> info ""
191+
> To verify that the IAM role is created, navigate to the AWS console and open the IAM Management Console. On the Permissions tab, verify that there is a `segment-s3-putobject` Permissions policy.
192+
103193

104194
### Add the AWS S3 with IAM Role Support Destination
105195

@@ -126,7 +216,7 @@ To finish configuration, enable the AWS S3 Destination with IAM Role Support des
126216

127217
To migrate an existing Amazon S3 destination to the AWS S3 with IAM Role Support Destination:
128218

129-
1. Configure the IAM role and IAM policy permissions as described in steps 2 - 4 [above](#create-an-iam-role-in-aws).
219+
1. Configure the IAM role and IAM policy permissions as described in steps 2 - 4 [above](#create-an-iam-role-in-the-aws-console).
130220
2. Add the AWS S3 with IAM Role Support Destination and add the AWS Region and IAM role ARN. For the bucket name, enter `<YOUR_BUCKET_NAME>/segment-logs/test`. Enable the destination, and verify data is received at `<YOUR_BUCKET_NAME>/segment-logs/test/segment-logs`. If the folder receives data, continue to the next step. If you don't see log entries, check the trust relationship document and IAM policy attached to the role.
131221
3. Update the bucket name in the new destination to `<YOUR_BUCKET_NAME>`.
132222
4. After 1 hour, disable the original Amazon S3 destination.
@@ -158,7 +248,7 @@ Segment groups logs by day, and names them using the following format:
158248

159249
s3://{bucket}/segment-logs/{source-id}/{received-day}/filename.gz
160250

161-
The received-day refers to the UTC date unix timestamp, that the API receives the file, which makes it easy to find all calls received within a certain timeframe.
251+
The received-day refers to the UTC date Unix timestamp, that the API receives the file, which makes it easy to find all calls received within a certain timeframe.
162252

163253
## Encryption
164254

0 commit comments

Comments
 (0)