2013年10月15日 星期二

[實驗]透過IAM 給予EMR Instance 特定權限

EMR 與 S3


EMR 最大的特色之一就是跟S3的整合,EMR可以直接把S3當做HDFS來使用,而且S3到EMR Instance 之間的傳輸費用是Free,當然要好好利用一下啦。
在EMR中使用S3方法很簡單,只要使用以下指令:
hadoop fs -cat s3n://<your bucket name>/test
or
hadoop fs -cat s3://<your bucket name>/test 
這時候問題來了....那S3要設定怎樣的權限? 如何讓EMR存取?這時候就要使用IAM

Why IAM?


使用IAM的好處就如同EMR 的開發文件裡面所說的 - Configure IAM Roles for Amazon EMR
An AWS Identity and Access Management (IAM) role is a way to delegate access so IAM users or services in AWS can act on your AWS resources. You create an IAM role and assign permissions to it, such as the ability to read and write data in one of your Amazon S3 buckets. When an IAM user or a service in AWS assumes that IAM role, they gain the specified permissions to access your AWS resources.
Amazon EMR uses IAM roles so that applications running on the EC2 instances of your cluster can access your AWS resources without the need to distribute your AWS account or IAM user credentials to those EC2 instances
簡單來說就是使用IAM 的設定以後,理論上我就不需要把我的accessKey 和 secureKey 設定到每一台instance裡面,就可以直接存取AWS Resource 的資源。
不過這邊要注意的是,啟動IAM 的權限只能透過API 或是CLI ,並不能透過AWS Management Console 來啟動。
Launching a cluster with IAM roles is currently not supported in the Amazon EMR console. If you need to use IAM roles in your cluster, launch the cluster using the CLI or the API.

測試結果


明明沒有設定IAM EMR也可以存取S3啊? 設定了以後到底差別在哪裡? 原來....
如果從EMR console create cluster (沒有設定IAM),EMR會自動把會把accesskey 和 securekey 存放在core-site.xml 裡面:
    fs.s3n.awsSecretAccessKey 
    fs.s3n.awsAccessKeyId
但是如果使用IAM,並且給予S3的權限,所以在你的core-site.xml 裡面就不會有SecureKey和AccessKey的出現。


謎之音:
其實我只是要測試用stackedit 寫寫看blog~ 結果似乎不如預期...囧rz...好多效果都沒出來...是因為我把bloger搞的太花俏用太多plugin了嘛?Orz...


沒有留言 :