Skip to content

Commit cbe2b23

Browse files
authored
Allow AWS Profile for CloudWatch Send
1 parent 0439f8f commit cbe2b23

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cloudwatchmon/cli/put_instance_stats.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ def __add_metric_dimensions(self, name, unit, value, common_dims, dims):
174174
metric_dims.update(dim)
175175
self.dimensions.append(metric_dims)
176176

177-
def send(self, verbose):
177+
def send(self, verbose, awsProfile):
178178
boto_debug = 2 if verbose else 0
179179

180180
# TODO add timeout
181-
conn = boto.ec2.cloudwatch.connect_to_region(self.region,
181+
conn = boto.ec2.cloudwatch.connect_to_region(self.region, profile_name=awsProfile,
182182
debug=boto_debug)
183183

184184
if not conn:
@@ -338,6 +338,9 @@ def config_parser():
338338
parser.add_argument('--version',
339339
action='store_true',
340340
help='Displays the version number and exits.')
341+
parser.add_argument('--aws-profile-name',
342+
action='store',
343+
help='Use AWS profile of this name when posting to CloudWatch.')
341344

342345
return parser
343346

@@ -569,12 +572,17 @@ def main():
569572
if args.verbose:
570573
print('Request:\n' + str(metrics))
571574

575+
# Check for AWS profile
576+
awsProfile = None
577+
if args.aws_profile_name:
578+
awsProfile = args.aws_profile_name
579+
572580
if args.verify:
573581
if not args.from_cron:
574582
print('Verification completed successfully. '
575583
'No actual metrics sent to CloudWatch.')
576584
else:
577-
metrics.send(args.verbose)
585+
metrics.send(args.verbose, awsProfile)
578586
if not args.from_cron:
579587
print('Successfully reported metrics to CloudWatch.')
580588
except Exception as e:

0 commit comments

Comments
 (0)