I would like to add another solution.
Yes, you can see them in AWS Cloudwatch Logs, but you need a bit of configuration.
Here the PR which introduced the feature.
You already have everything installed if you get the latest Amplify version (quite everything for React Native users, see later).
Setup the add-on:
Amplify.configure({
Logging: {
logGroupName: '<loggroup-name>',
logStreamName: '<logstream-name>',
region: '<region-code>',
},
...awsconfig,
});
const logger = new Logger('yourloggername', 'DEBUG');
Amplify.register(logger);
logger.addPluggable(new AWSCloudWatchProvider());
Now you can log to cloudwatch:
logger.debug('hello logging');
You need to configure IAM in AWS, I report a working example for simplicity.
Add this policy to the IAM identity you are using to access Cloudwatch:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "logs:DescribeLogGroups",
"Resource": "arn:aws:logs:<region-code>:<youraccount>:log-group:*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:DescribeLogStreams"
],
"Resource": "arn:aws:logs:<region-code>:<youraccount>:log-group:<loggroup-name>:log-stream:"
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:<region-code>:<youraccount>:log-group:<loggroup-name>:log-stream:<logstream-name>"
}
]
}
And you are ready to log to CloudWatch.
I do not know why this feature is not described in the official documentation.
Last but not least, if you are using React Native like me, you will not have util
package and TextExncoder()
utility. For me it was enought to install a polyfill like this one:
npm install fastestsmallesttextencoderdecoder
and import it as the first line in my index.js:
import 'fastestsmallesttextencoderdecoder';