rainit2006 / My_AWS-Cloud

0 stars 0 forks source link

AWS #5

Open rainit2006 opened 7 years ago

rainit2006 commented 7 years ago

AWS応用例

rainit2006 commented 6 years ago

http://media.amazonwebservices.com/jp/csd20140909/TA-02.pdf

S3和EBS

  1. S3适合需要长期持久存储的内容;
  2. S3容量更大(1byte到5TB,单个文件大小为5GB),EBS最大为1TB;
  3. S3文件不是存储在文件系统上,需要通过命令行访问;
  4. S3可以跨EC2访问,EBS只能通过EC2访问;
  5. S3比EBS便宜;
  6. EBS比S3快;

S3について •Amazon EC2上から外部のデータサーバーとしてアクセスできる。 •HTTPリクエストでどこからでもアクセス可能 Amazon S3 represents an object storage for data that deals with user files like Google Docs does it (flat file structure). Amazon S3 stores data as objects in a flat environment (without a hierarchy). Each object (file) in the storage contains a header with associated sequence of bytes from 0 byte to 5 TB. Objects in Amazon S3 are associated with a unique identifier (key), so access to them can be obtained through web requests from anywhere. As compared to Amazon EBS, the process of requesting an object in Amazon S3 is slower, but Amazon S3 is a highly scalable storage service with 99,999999999% data durability. Thus, it’s better to use it to store and deliver objects that don’t require a lot of read/write operations

EBSについて •Amazon EC2上のインスタンスからボリュームをマウントし、利用する。 「Amazon EBS」では、1GB~1TBまで1GB単位で仮想ディスクを生成することが可能です。通常利用の他にも、RAID0のように複数のボリュームを束ねて(ストライピング)使うことで高いI/Oパフォーマンスを実現させる使い方ができます。また、EBSボリュームのスナップショットを「Amazon S3」のストレージ上に保存させるようなAPIも公開されています。 Amazon EBS is an example of a block level storage similar to your desktop’s drive or virtual disk in virtualized environments. It’s important as once you configure the volume in Amazon EBS, it can’t be easily scaled. If you need more storage space, you will need to buy and configure a new volume of a bigger size.

考察 •EBS側に置くと良さげなデータ ◦各種ログやDBデータなど頻繁にインスタンスからアクセスするデータ ◦外からアクセスする必要の無いデータ •S3側に置くと良さげなデータ ◦画像ファイルなどの静的ファイル系データ ◦イメージファイルなどやバックアップファイルなどファイルサイズが大きく、あまりアクセスしないもの ◦HTTP経由でアクセスできる必要があるデータ


Amazon Glacierとは? バックアップやアーカイブのために開発された、セキュアかつ堅牢性の高いストレージ Amazon S3と同等の99.999999999%の耐久性を確保しつつ、S3の約1/3の費用で利用できる データの取り出し命令を発行してから実際にデータを取り出せる状態になるまで、通常3~5時間の時間が必要 オンプレミス環境ではテープライブラリに保存するような、各種ログやバックアップデータなどの大容量でアクセス頻度の低いデータの長期保存に最適 S3連携機能: S3BucketにLifecycleポリシーを設定すると、一定期間が経過したファイルは自動的にGlacierに待避される

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

EC2有四种pricing方式: 1, On demand: 按小时收费 オンデマンドインスタンスでは、長期間の契約や前払いは必要なく、コンピューティング性能に対して時間あたりの料金をお支払いいただきます。 通常、EC2インスタンスを起動すればこの費用体系が適用されます。

  1. リザーブドインスタンス(Reserved Instances ) 一定期間の継続利用をコミットすることで、割引を受けられる購入オプションです。
  2. スポットインスタンス(Spot Instances ) 起動できない or 強制終了されるリスクを負うことで、大幅にコスト削減が可能な購入方法です。 変動するスポット価格に対し、希望価格設定して入札します。入札価格がスポット価格を上回っていればインスタンスが起動しますが、スポット価格が高騰し入札価格を上回るとインスタンスは強制的に終了(Terminate)させられます。
  3. Dedicated Hosts
rainit2006 commented 6 years ago
rainit2006 commented 6 years ago

CloudFormation https://dev.classmethod.jp/beginners/chonyumon-cloudformation/ image

项目里利用Boto来实现cloudformation生成的程序实现。 http://boto3.readthedocs.io/en/latest/reference/services/cloudformation.html Boto は Python のパッケージで、 Amazon S3 を含む AWS へのインターフェイスです。


CloudFormationの要素

AWSTemplateFormatVersion: "version date" #必須:2010−09−09で固定

Description: #任意:テンプレートの説明
  String

Metadata: #任意:テンプレートに関する追加情報
  template metadata

Parameters: #任意:テンプレートに渡すことができる値
  set of parameters

Mappings: #任意:条件によるキーと値のマッピング
  set of mappings

Conditions: #任意:条件の定義
  set of conditions

Transform: #任意:AWS Serverless Application Modelのバージョンを指定
  set of transforms

Resources: #必須:スタックで構築するリソースを指定
  set of resources

Outputs: #任意:スタックのプロパティから返される値の表示
  set of outputs

https://dev.classmethod.jp/cloud/aws/cloudformation-beginner01/ image

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  FirstVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      Tags:
      - Key: Name
        Value: FirstVPC
  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: Name
        Value: FirstVPC-IGW
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref FirstVPC
      InternetGatewayId: !Ref InternetGateway
  FrontendRouteTable:
    Type: AWS::EC2::RouteTable
    DependsOn: AttachGateway
    Properties:
      VpcId: !Ref FirstVPC
      Tags:
      - Key: Name
        Value: FirstVPC-FrontendRoute
  FrontendRoute:
    Type: AWS::EC2::Route
    DependsOn: AttachGateway
    Properties:
      RouteTableId: !Ref FrontendRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
  FrontendSubnet:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      CidrBlock: 10.0.1.0/24
      MapPublicIpOnLaunch: 'true'
      VpcId: !Ref FirstVPC
      Tags:
      - Key: Name
        Value: FirstVPC-FrontendSubnet
  FrontendSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref FrontendSubnet
      RouteTableId: !Ref FrontendRouteTable

Fn::GetAtt  :指定されたオブジェクトから特定の属性値を取得します。

Fn::Base64  : EC2にミドルウェアを設定する時に環境固有の情報をパラメータから入力します。しかし日本語のようなマルチバイト文字を入力すると全て『?』と表示されてしまう。結論として、マルチバイト文字を入力する方法はありませんでした。EC2のUserDataやMetadataへ流し込む時にマルチバイトが文字化けしてしまいます。その代わり一旦ASCII文字に変換すれば、ASCII文字を入力することになるので使用できることがわかりました。CloudFormationで使用できる組み込み関数の中でASCII文字に変換できるのはFn::Base64です。Fn::Base64を使用してBase64エンコーディングしてASCII文字として入力します。 image https://dev.classmethod.jp/cloud/aws/cfn-multibyte-character-input/

Conditions 定义一些条件,在Resource里可以指定某个条件,当满足这个条件时才有效。 可参考下面URL里的例子。 https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html テスト環境と本稼働環境など、異なるコンテキストでリソースを作成できるテンプレートを再利用する場合に、条件を使用することがあります。テンプレートで EnvironmentType 入力パラメーターを追加できます。このパラメーターは入力として prod または test を受け取ることができます。本稼働環境では特定の機能に Amazon EC2 インスタンスを含め、テスト環境ではコスト削減のために使用する機能数を減らす場合があります。条件を使用すると、どのリソースを作成するかや、それらを各環境タイプでどのように設定するかを定義できます。

AWS::Region AWS CloudFormation によって事前定義されたパラメータ(擬似パラメーター)です。テンプレートでは宣言しません。 他の疑似パラメータ: AWS::AccountId : スタックが作成されているアカウントの AWS アカウント ID。 AWS::Partition、AWS::StackNameなど https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html

スタックを作成した結果分かったことを教えて欲しい「アウトプット」 https://dev.classmethod.jp/cloud/aws/cloudformation-firstcontact/ スタックが完成した後、CloudFormationのOutputsというタブで、この情報が確認できるようになります。 image

cfn-init https://dev.classmethod.jp/cloud/aws/cfn-init/ 「機能特化したAMIは作らず、プレーンなAMIにUserDataを与え、起動したら勝手に特化するように仕組む」という場面に利用。CloudFormationはcfn-initというヘルパースクリプトを用意しています。

cfn-initは、CloudFormationテンプレートのMetadataに書いた内容を読み込んで処理してくれる。 $ cfn-init -s STACK_NAME -r Logical_ID --region REGION STACK_NAME | CloudFormationのスタック名 Logical ID | Resourceの名前。 REGION | リージョン image

UserData UserDataに定義したスクリプトが実行されます。 httpdインストールしましょうか?

    "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash\n",
      "yum -y update\n",
      "yum -y install httpd\n",
      "chkconfig httpd on\n",
      "service httpd start\n"
    ]]}}

User Dataの指定方法 "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [〜]]}} というのはイディオムなので覚えておきましょう。

rainit2006 commented 6 years ago

Boto Boto は Python のパッケージで、 Amazon S3 を含む AWS へのインターフェイスです。

rainit2006 commented 6 years ago

VPC Virtual Private Cloud (VPC) は、AWS アカウント専用の仮想ネットワークです。VPC は、AWS クラウドの他の仮想ネットワークから論理的に切り離されており、AWS のリソース (例えば Amazon EC2 インスタンス) を VPC 内に起動できます。

VPC を作成するときに、その VPC に対して、IPv4 アドレスの範囲を Classless Inter-Domain Routing (CIDR) ブロックの形式で指定する必要があります (例: 10.0.0.0/16)。これは VPC のプライマリ CIDR ブロックです。

次の図は、IPv4 CIDR ブロックとメインルートテーブルがある新しい VPC を示しています。 image

IPv4 用の VPC とサブネットのサイズ設定 VPC を作成するときに、その VPC の IPv4 CIDR ブロックを指定する必要があります。許可されるブロックサイズは、/16 ネットマスク(65,536 個の IP アドレス)から /28 ネットマスク(16 個の IP アドレス)の間です。VPC を作成したら、VPC とセカンダリ CIDR ブロックを関連付けることができます。詳細については、「IPv4 CIDR ブロックを VPC に追加する」を参照してください。

VPC を作成する場合は、/16RFC 1918 に指定されているように、プライベート IPv4 アドレス範囲から CIDR ブロック ( 以下) を指定することをお勧めします。 10.0.0.0 - 10.255.255.255 (10/8 プレフィックス) 172.16.0.0 - 172.31.255.255 (172.16/12 プレフィックス) 192.168.0.0 - 192.168.255.255 (192.168/16 プレフィックス) https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Subnets.html

サブネットをインターネットに接続 サブネットをインターネットに接続するには、「インターネットゲートウェイ(Internet Gateway)」を用いる。これは、「自分のネットワークにインターネット回線を引き込む」というイメージの作業。 インターネットゲートウェイを作成する [Internet Gateways] > [Create Internet Gateway] VPC領域に結びつける. 作成したインターネットゲートウェイにチェックをつけてから、[Attach to VPC]をクリック。結びつけるVPC領域を選択。

インターネットゲートウェイ EC2::InternetGateway インターネットゲートウェイは、VPC のインスタンスとインターネットとの間の通信を可能にする VPC コンポーネント。 インターネットゲートウェイは 2 つの目的を果たします。1 つは、インターネットでルーティング可能なトラフィックの送信先を VPC のルートテーブルに追加することです。もう 1 つは、パブリック IPv4 アドレスが割り当てられているインスタンスに対してネットワークアドレス変換 (NAT) を行うことです。 インターネットゲートウェイは、IPv4 トラフィックおよび IPv6 トラフィックをサポートしています。 https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html

ルートテーブル VPC の各サブネットをルートテーブルに関連付ける必要があります。サブネットのルーティングは、このテーブルによってコントロールされます。1 つのサブネットは同時に 1 つのルートテーブルにしか関連付けることはできませんが、異なる複数のサブネットを 1 つのルートテーブルに関連付けることはできます。

各サブネットをルートテーブルに関連付ける必要があります。サブネットのルーティングは、このテーブルによってコントロールされます。サブネットを特定のルートテーブルに明示的に関連付けないと、そのサブネットは、メインルートテーブルに暗示的に関連付けられます。 https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Route_Tables.html

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 常識: サブネット化のメリット サブネット化しない場合の問題点: 1.ホストの台数が増えることによって同じネットワークだと余計な通信が発生します。余計な通信とはブロードキャストです。ブロードキャストは、同じネットワークに対して出す通信です。 2.セキュリティの問題。 例えば人事部が持っている社員の評価が書いてあるデータを他の部門の人にアクセスさせたくない場合。同じネットワークにいるとセキュリティを高めることがすごく難しくなります。

サブネットに分割する理由

  1. 物理的な隔離 片方のサブネットが障害を起こしても、もう片方に影響が出にくくなる。
  2. セキュリティ上の理由 サブネットを分けるとそれぞれに対して、別のネットワーク設定ができるため、「経理部のネットワーク」だけを分離して、他の部署からはアクセスできないようにしたい、などを実現することが可能。

サブネットマスク IPアドレスの32ビットのうち何ビットをネットワークアドレスに使うのかを定義するための32ビットの数値のことです。例:「192.168.1.0/24」または「192.168.1.0 255.255.255.0」

image

現在の日本国内の社内ネットワークなどで最も使用されているサブネット化は、クラスAまたはクラスBのネットワークで「ホスト部を 8 ビットだけにする」というパターンです。つまり、1つのネットワークに最大254台のホスト数が、ブロードキャストの分割、IPアドレス計画、ルーティング設計、セキュリティの観点から最も都合が良いからです。 image

什么是公有IP地址(公网IP): 组建一个企业级网络,需要去向“电信运营商ISP”申请一个接入Internet的宽带,同时ISP还会给我们分配一个或多个IP地址,这些IP地址可以供我们企业内部上网,这些ISP分配给我们的IP,就是公有IP。 公有地址(Public address,也可称为公网地址)由Internet NIC(Internet Network Information Center因特网信息中心)负责。这些IP地址分配给注册并向Internet NIC提出申请的组织机构。通过它直接访问因特网,它是广域网范畴内的。

什么是私有IP地址(私网IP): 我们企业或家庭内部组建局域网用的IP,一般都会用私有IP。 私有地址(Private address,也可称为专网地址)属于非注册地址,专门为组织机构内部使用,它是局域网范畴内的,私有IP禁止出现在Internet中,在ISP连接用户的地方,将来自于私有IP的流量全部都会阻止并丢掉。 如果在企业内部的电脑要访问Internet,则需要在企业边界上用“NAT技术”将私网IP转成公网IP才能正常的上网。

局域网在选取使用私有地址时,一般会按照实际需要容纳的主机数来选择私有地址段。常见的局域网由于容量小,一般选择C类的192.168.0.0作为地址段使用,一些大型企业就需要使用B类甚至A类地址段作为内部网络的地址段。最后需要补充说明的是,由于NAT和子网掩码的存在,实际在使用中,一个C类大小的局域网也可以选择A类的10.0.0.0网段作为自己的IP地址段。大多数局域网之所以仍然选择192.168.0.0/24或者192.168.1.0/24作为自己的IP地址段,更多的是因为约定成俗或者说网管个人习惯的关系。

NAT NATとは. NAT(Network Address Translation)はIPアドレスを変換する技術です。一般的には、プライベート IPアドレスをグローバルIPアドレスに変換する技術とされています。インターネットでは、グローバル IPアドレスを使用して構築したネットワークですが、企業ネットワークでは、プライベートIPアドレス を使用して構築されたネットワークなので、企業LANネットワークのクライアントPCがインターネット 接続する場合、プライベートIPアドレスをグローバルIPアドレスに変換(NAT)をする必要があります。 image

rainit2006 commented 6 years ago

Availability Zone (AZ) 各リージョンは完全に独立しています。各アベイラビリティーゾーンは独立していますが、同じリージョン内のアベイラビリティーゾーンどうしは低レイテンシーのリンクで接続されています。 image

リージョンというのは、 東京 や バージニア 、 サンパウロ などです。リージョンはそれぞれ、地理的に離れた領域です。1 つのリージョンに複数のそれぞれ独立したロケーションがあり、このロケーションを「アベイラビリティーゾーン」といいます。Amazon EC2 では、お客様がインスタンスなどのリソースとデータを複数のロケーションに配置できます。複数のリージョンにまたがってリソースのレプリケーションを行うには、お客様がそのように指定する必要があります。

インターネットゲートウェイ https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html インターネットゲートウェイは、VPC のインスタンスとインターネットとの間の通信を可能にする VPC コンポーネント。

VPC はインターネットとは切り離された存在です。VPC とインターネットの中継ポイントとしてインターネットゲートウェイを作成する必要があります。Internet Gateways の Create Internet Gateway から作成します。 Name tag: mygateway 作成したら Attach to VPC で myvpc にアタッチします。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー NAT ゲートウェイ ネットワークアドレス変換 (NAT) ゲートウェイを使用して、プライベートサブネットのインスタンスからはインターネットや他の AWS サービスに接続できるが、インターネットからはこれらのインスタンスとの接続を開始できないようにする。 https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html image

NAT ゲートウェイを作成するには、NAT ゲートウェイの常駐先のパブリックサブネットを指定する必要があります。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー ルートテーブル https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Route_Tables.html#RouteTables 各サブネットをルートテーブルに関連付ける必要があります。サブネットのルーティングは、このテーブルによってコントロールされます。サブネットを特定のルートテーブルに明示的に関連付けないと、そのサブネットは、メインルートテーブルに暗示的に関連付けられます。

Each route in a table specifies a destination CIDR and a target (for example, traffic destined for the external corporate network 172.16.0.0/12 is targeted for the virtual private gateway). テーブル内の各ルートは送信先 CIDR とターゲットを指定します (たとえば、送信先が外部の企業ネットワーク 172.16.0.0/12 のトラフィックのターゲットは仮想プライベートゲートウェイです)。AWS では、トラフィックと一致する最も具体的なルートを使用して、トラフィックをルーティングする方法を決定します。

Every route table contains a local route for communication within the VPC over IPv4. If your VPC has more than one IPv4 CIDR block, your route tables contain a local route for each IPv4 CIDR block. If you've associated an IPv6 CIDR block with your VPC, your route tables contain a local route for the IPv6 CIDR block. You cannot modify or delete these routes.

インターネットゲートウェイ、Egress-Only インターネットゲートウェイ、仮想プライベートゲートウェイ、NAT デバイス、ピアリング接続、または VPC エンドポイントを VPC に追加するときに、これらのゲートウェイまたは接続を使用するサブネットのルートテーブルを更新する必要があります。 VPC ごとに、作成できるルートテーブルの数と、ルートテーブルごとに追加できるルートの数には制限があります。

例:
Destination: 192.168.0.0/16 (VPC のプライベートアドレス空間)
Target: local

このエントリによって、この VPC 内のインスタンスが相互に通信できるようになります。 Target local とは VPC 内に存在するはずだから適切なサブネットにルーティングすればよいという AWS VPC 独特の表記です。これによってサブネット間の通信が可能になっています。こちらの記事で想像されているように、仮想ルータ同士はお互いに接続されているのです。

0.0.0.0/0 is also known as default. You can call it "everything else" other than what is already specified in your routing table.

Amazon VPC の制限 https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Appendix_Limits.html

ルーティングテーブル ルーターやネットワーク接続されたコンピュータが持つ、個々のネットワークの宛先への経路の一覧を保持しているテーブル状のデータ構造である。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー Elastic IP 動的なクラウドコンピューティング向けに設計された静的なパブリック IPv4 アドレスです。 Elastic IP アドレスは、アカウントのすべての VPC の任意のインスタンスまたはネットワークインターフェイスに関連付けることができます。 image


rainit2006 commented 6 years ago

Amazon EC2 リソースにタグを付ける https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/Using_Tags.html

タグを使用すると、AWS リソースを目的、所有者、環境などさまざまな方法で分類することができます。 タグはそれぞれ、1 つのキーとオプションの 1 つの値で構成されており、どちらもお客様側が定義します。 図の中では、インスタンスのそれぞれに 2 つのタグを割り当てています。1 つは Owner、もう 1 つは Stack という名前です。各タグには値も関連付けられています。 image

タグには以下のような基本制限があります。

  1. リソースあたりのタグの最大数 :  50
  2. キーの最大長 - 127 文字 (Unicode) (UTF-8)
  3. 値の最大長 - 255 文字 (Unicode) (UTF-8)
  4. タグのキーと値は大文字と小文字が区別されます。
  5. タグの名前または値に aws: プレフィックスは使用しないでください。このプレフィックスは AWS 用に予約されています。
  6. 複数のサービス間およびリソース間でタグ付けスキーマを使用する場合、他のサービスでも許可される文字に制限が適用されることがあるのでご注意ください。一般的に使用が許可される文字は、UTF-8 で表現できる文字、スペース、および数字と、+、-、=、.、_、:、/、@ などの特殊文字です。
rainit2006 commented 6 years ago

リソース Amazon EC2 にはさまざまなリソースが用意されており、それらを作成して利用することができます。これらのリソースには、イメージ、インスタンス、ボリューム、スナップショットなどがあります。リソースを作成すると、リソースに一意のリソース ID が割り当てられます。

rainit2006 commented 6 years ago

セキュリティグループ セキュリティグループは、インスタンスの仮想ファイアウォールとして機能し、インバウンドトラフィックとアウトバウンドトラフィックをコントロールします。

VPC 内でインスタンスを起動した場合、そのインスタンスには最大 5 つのセキュリティグループを割り当てることができます。

セキュリティグループは、サブネットレベルでなくインスタンスレベルで動作します。

セキュリティグループごとに、インスタンスへのインバウンドトラフィックをコントロールするルールと、アウトバウンドトラフィックをコントロールする一連のルールを個別に追加します。

セキュリティグループとネットワーク ACL の基本的な違い https://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/VPC_Security.html#VPC_Security_Comparison image

image

ネットワークACL image

rainit2006 commented 6 years ago

ブロックデバイスマッピングの例 https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html image

image

rainit2006 commented 6 years ago

IAM

  1. Lock Away Your AWS Account Root User Access Keys

  2. Create Individual IAM Users

  3. Use AWS Defined Policies to Assign Permissions Whenever Possible

  4. Use Groups to Assign Permissions to IAM Users All the users in an IAM group inherit the permissions assigned to the group. That way, you can make changes for everyone in a group in just one place. As people move around in your company, you can simply change what IAM group their IAM user belongs to.

  5. Grant Least Privilege One feature that can help with this is the Access Advisor tab. This tab is available on the IAM console details page whenever you inspect a user, group, role, or policy. The tab includes information about which services are actually used by a user, group, role, or by anyone that uses a policy. image

  6. Use Access Levels to Review IAM Permissions AWS categorizes each service action into one of four access levels based on what each action does: List, Read, Write, or Permissions management. You can use these access levels to determine which actions to include in your policies.

To see the access levels for a policy, you must first locate the policy's summary. The policy summary is included on the Policies page for managed policies, and on the Users page for policies that are attached to a user.

  1. Configure a Strong Password Policy for Your Users
  2. Enable MFA for Privileged Users For extra security, enable multi-factor authentication (MFA) for privileged IAM users (users who are allowed access to sensitive resources or APIs). With MFA, users have a device that generates a unique authentication code (a one-time password, or OTP). Users must provide both their normal credentials (like their user name and password) and the OTP.

The MFA device can either be a special piece of hardware, or it can be a virtual device (for example, it can run in an app on a smartphone).

  1. Use Roles for Applications That Run on Amazon EC2 Instances A role is an entity that has its own set of permissions, but that isn't a user or group. Roles also don't have their own permanent set of credentials the way IAM users do. In the case of Amazon EC2, IAM dynamically provides temporary credentials to the EC2 instance, and these credentials are automatically rotated for you.

When you launch an EC2 instance, you can specify a role for the instance as a launch parameter. Applications that run on the EC2 instance can use the role's credentials when they access AWS resources. The role's permissions determine what the application is allowed to do.

User是给人用,role是给App用(?)

  1. Delegate by Using Roles Instead of by Sharing Credentials You might need to allow users from another AWS account to access resources in your AWS account. If so, don't share security credentials, such as access keys, between accounts. Instead, use IAM roles.

  2. Rotate Credentials Regularly

  3. Remove Unnecessary Credentials

  4. Use Policy Conditions for Extra Security

  5. Monitor Activity in Your AWS Account You can use logging features in AWS to determine the actions users have taken in your account and the resources that were used. The log files show the time and date of actions, the source IP for an action, which actions failed due to inadequate permissions, and more.

# Policy Summary (List of Services) https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_understand-policy-summary.html Policies are summarized in three tables: the policy summary, the service summary, and the action summary. image image

Note: Amazon EC2 uses SSH keys, Windows passwords, and security groups to control who has access to the operating system of specific Amazon EC2 instances. There's no method in the IAM system to allow or deny access to the operating system of a specific instance.

Amazon S3 doesn't automatically give a user who creates a bucket or object permission to perform other actions on that bucket or object. Therefore, in your IAM policies, you must explicitly give users permission to use the Amazon S3 resources they create.

Logging IAM Events with AWS CloudTrail

rainit2006 commented 6 years ago

AMI

HVM AMIs 和 PV AMI https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/virtualization_types.html

HVM クラスタインスタンスがリリースされた際に HVM (Hardware-assited VM) という方式がサポート(というか必須)されました。 HVM AMIs are presented with a fully virtualized set of hardware and boot by executing the master boot record of the root block device of your image. This virtualization type provides the ability to run an operating system directly on top of a virtual machine without any modification, as if it were run on the bare-metal hardware. Unlike PV guests, HVM guests can take advantage of hardware extensions that provide fast access to the underlying hardware on the host system. All instance types support HVM AMIs.

rainit2006 commented 6 years ago

AWS Security Best Practices https://aws.amazon.com/jp/whitepapers/aws-security-best-practices/ https://d1.awsstatic.com/whitepapers/Security/AWS_Security_Best_Practices.pdf