AWS 镜像部署及CLI 相关 (不定期整理)

该博客介绍了如何使用AWS CLI来安装、上传文件到S3,并导入自定义镜像到EC2。步骤包括安装AWS CLI、上传镜像文件、创建角色、设置角色策略以及查询导入任务状态。此外,还提供了包含URL和bucket格式的containers.json示例文件。
摘要由CSDN通过智能技术生成

 

Table of Contents

安装AWS CLI

上传到S3

导入镜像:

建立角色:

角色策略:

参考:


安装AWS CLI

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

上传到S3

aws s3 cp ./vm-tpl01-100G.raw  s3://mk-vms

导入镜像:

aws ec2 import-image --disk-containers file://containers.json
或者
aws ec2 import-image --description "vm-tpl01" --disk-containers file:///home/ben/aws/containers.json

查询导入状态

aws ec2 describe-import-image-tasks \
    --import-task-ids import-ami-07fdabb84e2110b4f

containres.json (url格式)

[
  {
    "Format": "raw",
    "Url": "s3://mk-vms/vm-tpl01-20G.raw"
  },
  {
    "Description": "vm-tpl01-100G",
    "Format": "raw",
    "Url": "s3://mk-vms/vm-tpl01-100G.raw"
  }
]


containres.json (bucket格式)

[
  {
    "Description": "vm-tpl01",
    "Format": "raw",
    "UserBucket": {
        "S3Bucket": "mk-vms",
        "S3Key": "vm-tpl01.raw"
    }
  }
]

建立角色:

aws iam create-role --role-name vmimport --assume-role-policy-document file:///home/ben/aws/trust.json

trust.json

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}

角色策略:

aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file:///home/ben/aws/role-policy.json

 role-policy.json

 

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket" 
         ],
         "Resource":[
            "arn:aws:s3:::mk-vms",
            "arn:aws:s3:::mk-vms/*"
         ]
      },
      {
         "Effect":"Allow",
         "Action":[
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket",
            "s3:PutObject",
            "s3:GetBucketAcl"
         ],
         "Resource":[
            "arn:aws:s3:::export-image",
            "arn:aws:s3:::export-image/*"
         ]
      },
      {
         "Effect":"Allow",
         "Action":[
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource":"*"
      }
   ]
}

参考:

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html

https://docs.aws.amazon.com/cli/latest/reference/s3/#single-local-file-and-s3-object-operations

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bennybi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值