当前位置:   article > 正文

AWS CLI常用命令记录_awscli 清除configuration

awscli 清除configuration

关于Cli工具的安装就不多说了,到处都可以查到,这里主要记录下工作中常用的一些命令,因为官方文档的举例有时候并不完全,得亲自尝试才知道操作效果。

EC2:

  1. #修改实例类型,先stop
  2. aws ec2 stop-instances --instance-ids i-1234567890abcdef0
  3. aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --instance-type "{\"Value\": \"m1.medium\"}"
  4. ##创建安全组
  5. aws ec2 create-security-group --group-name test-sg --description "test-sg" --vpc-id vpc-abcd1234
  6. ##查看安全组
  7. aws ec2 --profile=prod describe-security-groups --group-ids sg-12345678abcdefghi
  8. #添加规则
  9. ##添加源安全组
  10. aws ec2 authorize-security-group-ingress --group-id sg-12345678abcdefghi --protocol tcp --port 6379 --source-group sg-12ab34cd
  11. ##给DB加IP源
  12. aws ec2 authorize-security-group-ingress --group-id sg-12345678abcdefghi --ip-permissions IpProtocol=tcp,FromPort=3306,ToPort=3306,IpRanges=[{CidrIp=3.210.××.××/32}]
  13. ##删除IP源
  14. aws ec2 revoke-security-group-ingress --group-id sg-12345678abcdefghi --ip-permissions IpProtocol=tcp,FromPort=3306,ToPort=3306,IpRanges=[{CidrIp=3.210.××.××/32}]
  15. #创建snapshot
  16. ##先找volume-id
  17. aws ec2 describe-instances --filters "Name=tag:Name,Values=webserver" --query "Reservations[*].Instances[*].[Tags[?Key==`Name`].Value,BlockDeviceMappings[*].Ebs.VolumeId]"
  18. vol-abcd1234
  19. ##再创建snapshot
  20. aws ec2 create-snapshot --volume-id vol-abcd1234 --tag-specifications "ResourceType=snapshot,Tags=[{Key=Name,Value=webserver}]"

ELB:

  1. ##ELB描述
  2. aws elb describe-load-balancers --load-balancer-name WebELB
  3. ##查看参数配置
  4. aws elb describe-load-balancer-attributes --load-balancer-name WebELB
  5. ##healthcheck:
  6. aws elb describe-instance-health --load-balancer-name WebELB
  7. ##修改healthcheck参数
  8. aws elb configure-health-check --load-balancer-name WebELB --health-check Target=HTTP:80/healthcheck,Interval=30,UnhealthyThreshold=5,HealthyThreshold=5,Timeout=8
  9. ##从ALB目标群组移除实例
  10. aws elbv2 deregister-targets --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789101:targetgroup/TestALB/abcdef12345abcde --targets Id=i-abcd1234
  11. ##注册实例到ALB目标群组
  12. aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789101:targetgroup/TestALB/abcdef12345abcde --targets Id=i-abcd1234

 S3:

  1. #ls
  2. ##查看默认的bucket
  3. aws s3 ls
  4. ##查看默认环境的abert-test内容
  5. aws s3 ls s3://abert-test
  6. ##查看目录大小,列出每个文件大小
  7. aws s3 ls --summarize --human-readable --recursive s3://bucket-name
  8. #cp
  9. ##上传本地文件
  10. aws s3 cp bstest.txt s3://abert-test
  11. ##复制文件
  12. aws s3 cp s3://mybucket/test.txt s3://mybucket/test2.txt
  13. ##递归拷贝
  14. aws s3 cp s3://mybucket . --recursive
  15. ##排除拷贝
  16. aws s3 cp myDir s3://mybucket/ --recursive --exclude "*.jpg"
  17. ##拷贝并添加ACL权限控制
  18. aws s3 cp s3://mybucket/test.txt s3://mybucket/test2.txt --acl public-read-write
  19. #rm
  20. ##删除对象
  21. aws s3 rm s3://mybucket/test.txt
  22. #mb
  23. ##创建bucket
  24. aws s3 mb s3://newbucket
  25. #rb
  26. ##删除bucket:
  27. aws s3 rb s3://bucket-name
  28. ##删除非空:
  29. aws s3 rb s3://bucket-name --force

DynamoDB

  1. ##创建DynamoDB表
  2. aws dynamodb create-table --table-name bettytest --attribute-definitions AttributeName=pk,AttributeType=N AttributeName=sk,AttributeType=N --key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
  3. ##修改DynamoDB表读写容量
  4. aws dynamodb update-table --table-name bettytest --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10
  5. ##删除DynamoDB表
  6. aws dynamodb delete-table --table-name betty-test
  7. ##加stream
  8. aws dynamodb update-table --table-name betty-test --stream-specification StreamEnabled=true,StreamViewType="NEW_AND_OLD_IMAGES"
  9. ##关闭stream
  10. aws dynamodb update-table --table-name betty-test --stream-specification StreamEnabled=false
  11. ##查看DynamoDB表
  12. aws dynamodb describe-table --table-name betty-test

Lambda:

  1. #function和DynamoDB之间每创建一次映射就生成一个UUID,同一个表如果建了多次就有多个映射关系
  2. #创建映射
  3. ##查找event-source-arn
  4. aws dynamodb describe-table --table-name Betty-test
  5. ##先给表开启stream
  6. aws dynamodb update-table --table-name Betty-test --stream-specification StreamEnabled=true,StreamViewType="NEW_AND_OLD_IMAGES"
  7. ##建立映射
  8. aws lambda create-event-source-mapping --event-source-arn "arn:aws:dynamodb:us-east-1:123456780123:table/Betty-test/stream/2019-11-11T03:35:20.612" --function-name IngestDynamoDBtest --starting-position LATEST
  9. ##查看映射关系
  10. aws lambda list-event-source-mappings --function-name IngestDynamoDBtest
  11. ##根据UUID查看
  12. aws lambda get-event-source-mapping --uuid abcd7h2s-ab12-492c-c2d3-fd34f45ag6h1
  13. ###启动/禁用映射关系
  14. aws lambda update-event-source-mapping --uuid abcd7h2s-ab12-492c-c2d3-fd34f45ag6h1 --function-name IngestDynamoDBtest --enabled
  15. ##删除无用的映射
  16. aws lambda delete-event-source-mapping --uuid abcd7h2s-ab12-492c-c2d3-fd34f45ag6h1

Elasticache

  1. #Memcache
  2. ##创建
  3. aws elasticache create-cache-cluster --cache-cluster-id bettytest --az-mode cross-az --preferred-availability-zones us-east-1a us-east-1d --num-cache-nodes 2 --cache-node-type cache.m4.large --engine memcached --engine-version "1.4.24" --cache-parameter-group-name bettycacheparameter --cache-subnet-group-name test-cache-subnet-group --security-group-ids "sg-abcd1234" "sg-1234abcd" --port 11211 --notification-topic-arn arn:aws:sns:us-east-1:123456780123:test-Alarm --preferred-maintenance-window sun:08:00-sun:09:00 --auto-minor-version-upgrade
  4. ##查看memcache集群信息
  5. aws elasticache describe-cache-clusters --cache-cluster-id bettytest
  6. ##新增节点
  7. aws elasticache modify-cache-cluster --cache-cluster-id bettytest --num-cache-nodes 3 --new-availability-zones ap-southeast-1a --apply-immediately
  8. ##删除节点
  9. aws elasticache modify-cache-cluster --cache-cluster-id bettytest --num-cache-nodes 1 --cache-node-ids-to-remove 0002 --apply-immediately
  10. ##删除两个节点
  11. aws elasticache modify-cache-cluster --cache-cluster-id bettytest --num-cache-nodes 1 --cache-node-ids-to-remove 0002 0003 --apply-immediately
  12. ##删除cache
  13. aws elasticache delete-cache-cluster --cache-cluster-id bettytest
  14. ##修改type --不支持
  15. aws elasticache modify-cache-cluster --cache-cluster-id bettytest --cache-node-type cache.m4.large --apply-immediately
  16. An error occurred (InvalidParameterCombination) when calling the ModifyCacheCluster operation: Scaling is not supported for engine memcached】
  1. #Redis
  2. ##创建redis集群
  3. aws elasticache create-replication-group --replication-group-id betty-redis --replication-group-description "betty-redis-test" --automatic-failover-enabled --num-cache-clusters 2 --cache-node-type cache.m3.medium --engine redis --engine-version 5.0.0 --cache-parameter-group-name default.redis5.0 --cache-subnet-group-name betty-cache-subnet-group --security-group-ids sg-0123abcd4567efghi
  4. ##查看redis集群
  5. aws elasticache describe-replication-groups --replication-group-id betty-redis
  6. ##修改备份保留期为1天
  7. aws elasticache modify-replication-group --replication-group-id betty-redis --snapshotting-cluster-id betty-redis-002 --snapshot-retention-limit 1

Kinesis:

  1. ##放入数据
  2. aws kinesis put-record --stream-name Betty_Stream --partition-key 123 --data testdata
  3. ##读取数据
  4. aws kinesis get-shard-iterator --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --stream-name Betty_Stream

SQS:

  1. ##读取消息
  2. aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/123456780123/MY_SQS_TEST --attribute-names All --message-attribute-names All --max-number-of-messages 1
  3. ##删除消息
  4. aws sqs delete-message --queue-url https://sqs.us-east-1.amazonaws.com/123456780123/MY_SQS_TEST --receipt-handle

SNS:

  1. ##查看所有的IOS push
  2. aws sns list-platform-applications

SES:

  1. ##查看已验证域名
  2. aws ses list-identities

IAM:

  1. ##为Application Auto Scaling创建服务角色
  2. aws iam create-role --role-name MyIAMAutoscalingServiceRole --assume-role-policy-document file://trust-relationship.json
  3. ##为服务角色创建 IAM 策略
  4. aws iam create-policy --policy-name MyIAMAutoscalingServicePolicy --policy-document file://service-role-policy.json
  5. arn:aws:iam::123456780123:policy/MyIAMAutoscalingServicePolicy
  6. ##将策略附加到服务角色
  7. aws iam attach-role-policy --role-name MyIAMAutoscalingServiceRole --policy-arn arn:aws:iam::123456780123:policy/MyIAMAutoscalingServicePolicy

持续更新。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/972713
推荐阅读
相关标签
  

闽ICP备14008679号