[AWS Kinesis Data Firehose] Cross-Account ํ™˜๊ฒฝ์—์„œ ๋‹ค๋ฅธ ๊ณ„์ •์˜ S3 Bucket์— ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ ์ŠคํŠธ๋ฆฌ๋ฐํ•˜๊ธฐ

2022. 6. 23. 00:40ใ†AWS

โ˜„๏ธ To-Be Architecture

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 ์ƒ์„ฑ

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 ๋ฒ„ํ‚ท์— ๋ฐ๋ชจ ๋ฐ์ดํ„ฐ๊ฐ€ ์ž˜ ๋“ค์–ด์™”์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์„ฑ๊ณต~~!

 

 

 


๐Ÿ”— ์ฐธ๊ณ  ๋งํฌ

  1. Wiki: Cross Account AWS S3 Bucket Delivery in Kinesis Firehose
  2. AWS Docs: Controlling Access with Amazon Kinesis Data Firehose
  3. AWS Docs: Amazon S3 ๋ฒ„ํ‚ท์— ์žˆ๋Š” ๊ฐ์ฒด์— ๋Œ€ํ•œ ๊ต์ฐจ ๊ณ„์ • ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ์ œ๊ณตํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?
  4. AWS CLI Doces: create-delivery-stream
  5. AWS Docs: Amazon Kinesis Data Firehose Firehose๋ž€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?