Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use AWS LightSail with AWS CloudWatch?

I've recently started testing out LightSail, but I would like to keep my logging centralized in CloudWatch, but cannot seem to find anything that would enable this. Interestingly LightSail instances do not appear in the EC2 Dashboard. I thought they were just EC2 instances beneath the surface.

like image 406
iksnae Avatar asked Jan 14 '17 00:01

iksnae


People also ask

Can Lightsail be in VPC?

Lightsail lets you connect to AWS resources, such as an Amazon RDS database, through virtual private cloud (VPC) peering. A VPC is a virtual network dedicated to your AWS account. Everything you create inside Lightsail is inside a VPC, and you can connect your Lightsail VPC to an Amazon VPC.

What is the difference between AWS and Lightsail?

Amazon EC2 is a mix of multiple services and has its own individual features used to create a single architecture. Amazon EC2 instances are meant for small to complex architecture. Lightsail, on other hand, is an integrated product of services offered by AWS. Lightsail is better for small to medium scale workloads.

Can Lightsail connect to RDS?

First, make sure you have an RDS database running the same engine in the same Region as your Lightsail instance, and in your default Amazon VPC. For example, if your Lightsail database is running MySQL in the Oregon Region, RDS should also be running MySQL in the Oregon Region and in the default VPC.


1 Answers

It's possible to get it working. The problem is that Lightsail instances are EC2 instances under the hood, but without access to all of the EC2 configuration. The CloudWatch agent documentation explains how to set up IAM roles for EC2 instances to assume, but Lightsail boxes only use a single role which can't be changed and can't be edited. As a result, you need to follow instructions for setting it up as an on-premise server.

The problem you will then hit is as David J Eddy saw in his answer:

2018-10-20T16:04:37Z E! WriteToCloudWatch failure, err:  AccessDenied: User: arn:aws:sts::891535117650:assumed-role/AmazonLightsailInstanceRole/i-0788a602f758b836f is not authorized to perform: cloudwatch:PutMetricData status code: 403, request id: b443ecc6-d481-11e8-a551-6d030b8667be

This is due to a bug in the CloudWatch agent which ignores the argument to use on-premise mode (-m onPremise) if it detects it is running on an EC2 instance. The trick is to edit the common-config.toml file to force using a local AWS CLI profile for authentication. You will need to add the following lines to that file (which can be found at /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml on Debian - the installation location is OS dependent):

[credentials]
shared_credential_profile = "AmazonCloudWatchAgent"

Restart the agent and it should start reporting metrics. I've put together a full tutorial here

like image 83
Cal Avatar answered Sep 20 '22 17:09

Cal