# 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
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文件
官网文档:
GetMetricData
get-metric-data
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
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
# 官方文档(也可以通过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 ***
(查看所有db实例,query后可以指定json输出的指定key)
aws rds describe-db-instances --query 'DBInstances[].{DBInstanceIdentifier:DBInstanceIdentifier}' --profile profile-name --output json
(列出所有elasticache)
aws elasticache describe-cache-clusters --query 'CacheClusters[].{ARN:ARN}' --output json --profile profile-name
(列出所有强制更新及更新涉及的实例)
# 因为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的详细用法
持续更新中