Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mappings:
CWLogs:
WebRequestLogGroup:
TimestampFormat: "%Y-%m-%dT%H:%M:%S.%f%z"
Outputs:
WebRequestCWLogGroup:
Description: "The name of the Cloudwatch Logs Log Group created for this environments web server access logs. You can specify this by setting the value for the environment variable: WebRequestCWLogGroup. Please note: if you update this value, then you will need to go and clear out the old cloudwatch logs group and delete it through Cloudwatch Logs."
Value: { "Ref" : "AWSEBCloudWatchLogsAppLogGroup"}
Resources :
AWSEBCloudWatchLogsAppLogGroup:
Type: "AWS::Logs::LogGroup"
DependsOn: AWSEBBeanstalkMetadata
DeletionPolicy: Retain
Properties:
LogGroupName:
"Fn::GetOptionSetting":
Namespace: "aws:elasticbeanstalk:application:environment"
OptionName: WebRequestCWLogGroup
DefaultValue: {"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "logs"]]}
RetentionInDays: 14
AWSEBAutoScalingGroup:
Metadata:
"AWS::CloudFormation::Init":
CWLogsAgentConfigSetup:
files:
"/tmp/cwlogs/conf.d/tomcat-catalina.conf":
content : |
[web_log]
file = /var/log/web-1.log
log_group_name = `{ "Ref" : "AWSEBCloudWatchLogsAppLogGroup" }`
log_stream_name = web
datetime_format = `{"Fn::FindInMap":["CWLogs", "WebRequestLogGroup", "TimestampFormat"]}`
[web_error_log]
file = /var/log/web-1.error.log
log_group_name = `{ "Ref" : "AWSEBCloudWatchLogsAppLogGroup" }`
log_stream_name = web-error
datetime_format = `{"Fn::FindInMap":["CWLogs", "WebRequestLogGroup", "TimestampFormat"]}`
mode : "000400"
owner : root
group : root
AWSEBCWLGreetingHitsMetricFilter :
Type : "AWS::Logs::MetricFilter"
Properties :
LogGroupName: { "Ref" : "AWSEBCloudWatchLogsAppLogGroup" }
FilterPattern : '{ $.fields_requested_uri = "/greeting"}'
MetricTransformations :
- MetricValue : 1
MetricNamespace: {"Fn::Join":["/", ["elastic-beanstalk", {"Ref":"AWSEBEnvironmentName"}]]}
MetricName : greeting-hits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment