[AWS Kinesis Data Firehose] Cross-Account ํ๊ฒฝ์์ ๋ค๋ฅธ ๊ณ์ ์ S3 Bucket์ ์ค์๊ฐ ๋ฐ์ดํฐ ์คํธ๋ฆฌ๋ฐํ๊ธฐ
2022. 6. 23. 00:40ใAWS
โ๏ธ To-Be Architecture
Cross-Account ํ๊ฒฝ์์ Firehose Data Stream์ ์ด์ฉํ์ฌ S3 ๋ฒํท์ ์ค์๊ฐ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ง์ ์ ์ก(Direct PUT) ๋ฐ ์ ์ฅํด๋ณด์.
๐ก Amazon Kinesis Data Firehose๋?
- ์๋์ ๋ชฉ์ ์ง๋ก ์ค์๊ฐ ์คํธ๋ฆฌ๋ฐ ๋ฐ์ดํฐ๋ฅผ ์ ์กํ ์ ์๋ AWS managed service
- AWS ์๋น์ค : Amazon S3, Amazon Redshift, Amazon OpenSearch Service, Splunk
- HTTP ์๋ํฌ์ธํธ
- ์จ๋ํํฐ ์๋น์ค(Datadog, Dynatrace, LogicMonitor, MongoDB, New Relic, Sumo Logic)๋ฅผ ์ด์ฉํ HTTP ์๋ํฌ์ธํธ
- ์ฌ์ฉ ๋ฐฉ๋ฒ : Kinesis Data Firehose ์ ์ก ์คํธ๋ฆผ์ ์์ฑํ ๋ค์ ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๋ค.
๐ซ Problem Solving
1. [A account] S3 Bucket ์์ฑ
- S3 ๋ฒํท ์ ์ฑ ์ ์ฉ
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow access from B account",
"Effect": "Allow",
"Principal": {
"AWS":"arn:aws:iam::{B-account-id}:root"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::{A-account-bucket-name}/*",
"arn:aws:s3:::{A-account-bucket-name}"
]
}
]
}
2. [B account] Firehose Delivery Stream์ ์ ์ฉํ IAM Policy ๋ฐ Role ์์ฑ
2-1. IAM Policy ์์ฑ
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": [
"s3:AbortMultipartUpload",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::{A-account-bucket-name}/*",
"arn:aws:s3:::{A-account-bucket-name}"
]
}
]
}
2-2. IAM Role ์์ฑ
- 2-1์์ ์์ฑํ IAM Policy๋ฅผ ์ฐ๊ฒฐ
- IAM Role์ ์ ๋ขฐ๊ด๊ณ(Trusted relationships) ์์
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "firehose.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "{B-account-id}"
}
}
}
]
}
(์ฐธ๊ณ : stsLExternalId ๊ฐ์ผ๋ก {A-account-id}๋ฅผ ๋ฃ๊ณ 3๋ฒ์ ์ํํ๋ฉด ์๋์ ๊ฐ์ด ์ถ๋ ฅ๋๋ฉฐ delivery stream์ด ์์ฑ๋์ง ์๋๋ค.)
An error occurred (InvalidArgumentException) when calling the CreateDeliveryStream operation: Firehose is unable to assume role arn:aws:iam::{B-account-id}:role/hyeonju-firehose-role. Please check the role provided.
3. [B account]์ ์ ์ํ ์ํ์์ AWS CLI๋ฅผ ์ด์ฉํ์ฌ Firehose ์ ์ก ์คํธ๋ฆผ์ ์์ฑํ๋ค.
- ์ฝ์์์ Firehose ์ ์ก ์คํธ๋ฆผ์ ์์ฑํ๋ ๊ฒฝ์ฐ ๋ค๋ฅธ ๊ณ์ ์ S3 ๋ฒํท์ ๋ชฉ์ ์ง๋ก ์ง์ ํ๋ ๊ฒ์ด ๋ถ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ AWS CLI๋ฅผ ์ด์ฉํ์ฌ ์์ฑํ๋ ๊ฒ์ ๊ถ์ฅํ๋ค.
aws firehose create-delivery-stream
--delivery-stream-name {delivery-stream-name}
--delivery-stream-type DirectPut
--extended-s3-destination-configuration RoleARN={2-2์์ ์์ฑํ IAM Role ARN},BucketARN={1์์ ์์ฑํ S3 Bucket ARN}
- ๋ค๋ฅธ ์ต์ ์ ์ฃผ๊ณ ์ถ๋ค๋ฉด ⇒ ์ฐธ๊ณ : AWS CLI Doces: create-delivery-stream
- ์ ๋ช ๋ น์ด๊ฐ ์ ์์ ์ผ๋ก ์คํ๋๋ฉด ์๋์ ๊ฐ์ ์ ์ก์คํธ๋ฆผ ARN์ด JSON ํ์์ผ๋ก ์ถ๋ ฅ๋๋ค.
{
"DeliveryStreamARN": "arn:aws:firehose:ap-northeast-2:{B-account-id}:deliverystream/{delivery-stream-name}"
}
4. ํ ์คํธ
- B Account๋ก AWS Kinesis ์ฝ์์ ์ ์ํ๋ฉด Delivery Stream์ด ์์ฑ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
- [Test with demo data] ํญ์์ [Start sending demo data] ๋ฒํผ์ ๋๋ฌ S3์ ์คํธ๋ฆฌ๋ฐ ๋ฐ์ดํฐ๋ฅผ ์ ์กํด๋ณด์.
- A Account์ S3 ๋ฒํท์ ๋ฐ๋ชจ ๋ฐ์ดํฐ๊ฐ ์ ๋ค์ด์์์ ํ์ธํ ์ ์๋ค.
์ฑ๊ณต~~!
๐ ์ฐธ๊ณ ๋งํฌ
- Wiki: Cross Account AWS S3 Bucket Delivery in Kinesis Firehose
- AWS Docs: Controlling Access with Amazon Kinesis Data Firehose
- AWS Docs: Amazon S3 ๋ฒํท์ ์๋ ๊ฐ์ฒด์ ๋ํ ๊ต์ฐจ ๊ณ์ ์ก์ธ์ค ๊ถํ์ ์ ๊ณตํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ๋์?
- AWS CLI Doces: create-delivery-stream
- AWS Docs: Amazon Kinesis Data Firehose Firehose๋ ๋ฌด์์ ๋๊น?