aws-cli相关操作

s3:

1.下载数据到本地:

# BUCKET1:桶名称
# dir/my_images.tar.bz2:s3中的对象
# my_images.tar.bz2 复制到本地的名称
# aws-cof:aws配置的项目名(将aksk配置到配件里,这样就不用在环境变量中写aksk了)
aws s3api get-object --bucket BUCKET1 --key dir/my_images.tar.bz2 my_images.tar.bz2 --profile aws-cof

2.下载多个文件到本地

ws s3 cp  s3://backet_name/ ./ --exclude "*"  --include "file_name.*.sql" --include "metadata"  --recursive --profile profile_name

# --recursive 针对多个文件操作
# --exclude 从命令中排除的文件,*指所有文件从命令中排除,可以多次使用--exclude指定
# --include 命令生效的文件,可以多次指定
# 上面语句的意思是仅拷贝bucket_name桶下的file_name.*.sql匹配的文件和metadata文件

CloudWatch:

官网文档:
GetMetricData
get-metric-data

1.用表达式查看监控事例

aws cloudwatch get-metric-data --metric-data-queries  '[{"Id": "m1","Period": 300,"ReturnData":true,"Expression": "SELECT AVG(DatabaseMemoryUsagePercentage) FROM \"AWS/ElastiCache\" GROUP BY CacheClusterId"}]' --start-time "1665380098"  --end-time "1665380398"    --output json   --profile abc

2.用MetricStat查看监控事例

aws cloudwatch get-metric-data --metric-data-queries  '[{"Id": "m1","MetricStat": {"Metric": {"Namespace": "AWS/ElastiCache","MetricName": "FreeableMemory","Dimensions": [{"Name": "CacheClusterId","Value":"cluster-id"}]},"Period": 300,"Stat": "Average"},"ReturnData":true,"Label": "123"}]' --start-time "1665380098"  --end-time "1665380398"    --output json   --profile abc

3.添加监控

# 官方文档(也可以通过cloudwatch中对应告警的查看源选项来查看)
https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-alarm.html
https://docs.aws.amazon.com/zh_cn/AmazonCloudWatch/latest/monitoring/PublishMetrics.html


# RDS
aws cloudwatch put-metric-alarm --alarm-name *** --metric-name CPUUtilization --namespace AWS/RDS --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanThreshold  --dimensions "Name=DBInstanceIdentifier,Value=***" --evaluation-periods 1 --alarm-actions *** --ok-actions *** --unit Percent --profile ***

# ElastiCache
aws cloudwatch put-metric-alarm --alarm-name *** --metric-name EngineCPUUtilization --namespace AWS/ElastiCache --statistic Average --period 300 --threshold 60 --comparison-operator GreaterThanOrEqualToThreshold  --dimensions '[{"Name":"CacheClusterId","Value":"***"},{"Name":"CacheNodeId","Value":"0001"}]' --evaluation-periods 1 --alarm-actions *** --ok-actions *** --unit Percent --profile ***

rds:

1.describe-db-instances

(查看所有db实例,query后可以指定json输出的指定key)

 aws rds describe-db-instances --query 'DBInstances[].{DBInstanceIdentifier:DBInstanceIdentifier}'  --profile profile-name --output json

elasticache:

1.describe-cache-clusters

(列出所有elasticache)

aws elasticache describe-cache-clusters --query 'CacheClusters[].{ARN:ARN}' --output json --profile profile-name

2.describe-service-updates,describe-update-actions

(列出所有强制更新及更新涉及的实例)

# 因为aws的elasticache redis的强制更新并没有邮件通知,所以依照下面两个cli做个邮件报警我觉得还是比较有用的
# 注意,这里不能写成--query 'ServiceUpdates[:1][?AutoUpdateAfterRecommendedApplyByDate==`true`].[*]',ServiceUpdates[:1]与筛选条件结合在一起不清楚为什么会出不来结果
aws elasticache describe-service-updates --profile profile_name --output=json --service-update-status=available  --query 'ServiceUpdates[?AutoUpdateAfterRecommendedApplyByDate==`true`].[ServiceUpdateName,ServiceUpdateRecommendedApplyByDate,ServiceUpdateDescription]'

# 查看没有应用的更新
aws elasticache describe-update-actions --profile profile_name --output=json --query 'UpdateActions[?UpdateActionStatus==`not-applied`].{"ReplicationGroupId":ReplicationGroupId,"ServiceUpdateName":ServiceUpdateName}'

官网文档: query的详细用法

持续更新中

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值