Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
385 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# metric-push-api | ||
|
||
This lambda takes http requests from the client side for never events e.g. | ||
fail to render. This would be the form of an img tag or similar. | ||
It will then push a metric to cloudwatch which we can then alarm on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// "Any .sbt files in foo, say foo/build.sbt, will be merged with the build definition for the entire build, but scoped to the hello-foo project." | ||
// https://www.scala-sbt.org/0.13/docs/Multi-Project.html | ||
name := "metric-push-api" | ||
description:= "HTTP API to push a metric to cloudwatch so we can alarm on errors" | ||
|
||
riffRaffPackageType := assembly.value | ||
riffRaffUploadArtifactBucket := Option("riffraff-artifact") | ||
riffRaffUploadManifestBucket := Option("riffraff-builds") | ||
riffRaffManifestProjectName := "MemSub::Membership Admin::Metric Push API" | ||
riffRaffArtifactResources += (file("handlers/metric-push-api/cfn.yaml"), "cfn/cfn.yaml") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Description: HTTP API to push a metric to cloudwatch so we can alarm on errors | ||
|
||
Parameters: | ||
Stage: | ||
Description: Stage name | ||
Type: String | ||
AllowedValues: | ||
- PROD | ||
- CODE | ||
Default: CODE | ||
|
||
Conditions: | ||
CreateProdMonitoring: !Equals [ !Ref Stage, PROD ] | ||
|
||
Mappings: | ||
StageMap: | ||
CODE: | ||
ApiName: metric-push-api-api-CODE | ||
DomainName: metric-push-api-code.membership.guardianapis.com | ||
PROD: | ||
ApiName: metric-push-api-api-PROD | ||
DomainName: metric-push-api-prod.membership.guardianapis.com | ||
|
||
Resources: | ||
|
||
MetricPushProxyResource: | ||
Type: AWS::ApiGateway::Resource | ||
Properties: | ||
RestApiId: !Ref MetricPushAPI | ||
ParentId: !GetAtt [MetricPushAPI, RootResourceId] | ||
PathPart: metric-push-api | ||
DependsOn: MetricPushAPI | ||
|
||
MetricPushMethod: | ||
Type: AWS::ApiGateway::Method | ||
Properties: | ||
AuthorizationType: NONE | ||
ApiKeyRequired: false | ||
RestApiId: !Ref MetricPushAPI | ||
ResourceId: !Ref MetricPushProxyResource | ||
HttpMethod: GET | ||
Integration: | ||
Type: MOCK | ||
IntegrationResponses: | ||
- StatusCode: 204 | ||
ResponseParameters: | ||
method.response.header.Cache-control: '''no-cache''' | ||
MethodResponses: | ||
- StatusCode: 204 | ||
ResponseParameters: | ||
method.response.header.Cache-control: true | ||
DependsOn: | ||
- MetricPushAPI | ||
- MetricPushProxyResource | ||
|
||
MetricPushAPI: | ||
Type: "AWS::ApiGateway::RestApi" | ||
Properties: | ||
Description: This called when we have a set of SF accounts that all belong to one person (email) to merge them | ||
Name: !FindInMap [StageMap, !Ref Stage, ApiName] | ||
|
||
MetricPushAPIStage: | ||
Type: AWS::ApiGateway::Stage | ||
Properties: | ||
Description: Stage for metric-push-api-api | ||
RestApiId: !Ref MetricPushAPI | ||
DeploymentId: !Ref MetricPushAPIDeployment | ||
StageName: !Sub ${Stage} | ||
MethodSettings: | ||
- ResourcePath: '/*' | ||
HttpMethod: '*' | ||
LoggingLevel: ERROR | ||
DataTraceEnabled: true | ||
DependsOn: MetricPushMethod | ||
|
||
MetricPushAPIDeployment: | ||
Type: AWS::ApiGateway::Deployment | ||
Properties: | ||
Description: Deploys metric-push-api-api into an environment/stage | ||
RestApiId: !Ref MetricPushAPI | ||
DependsOn: MetricPushMethod | ||
|
||
MetricPushDomainName: | ||
Type: "AWS::ApiGateway::DomainName" | ||
Properties: | ||
RegionalCertificateArn: # only for *.membership.guardianapis.com | ||
!Sub arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/c1efc564-9ff8-4a03-be48-d1990a3d79d2 | ||
DomainName: !FindInMap [ StageMap, !Ref Stage, DomainName ] | ||
EndpointConfiguration: | ||
Types: | ||
- REGIONAL | ||
|
||
MetricPushBasePathMapping: | ||
Type: "AWS::ApiGateway::BasePathMapping" | ||
Properties: | ||
RestApiId: !Ref MetricPushAPI | ||
DomainName: !Ref MetricPushDomainName | ||
Stage: !Sub ${Stage} | ||
DependsOn: | ||
- MetricPushAPI | ||
- MetricPushAPIStage | ||
- MetricPushDomainName | ||
|
||
MetricPushDNSRecord: | ||
Type: AWS::Route53::RecordSet | ||
Properties: | ||
HostedZoneName: membership.guardianapis.com. | ||
Name: !FindInMap [ StageMap, !Ref Stage, DomainName ] | ||
Comment: !Sub CNAME for metric-push-api API ${Stage} | ||
Type: CNAME | ||
TTL: '120' | ||
ResourceRecords: | ||
- !GetAtt [ MetricPushDomainName, RegionalDomainName ] | ||
DependsOn: | ||
- MetricPushDomainName | ||
|
||
5xxApiAlarm: | ||
Type: AWS::CloudWatch::Alarm | ||
Condition: CreateProdMonitoring | ||
Properties: | ||
AlarmActions: | ||
- !Sub arn:aws:sns:${AWS::Region}:${AWS::AccountId}:subscriptions_dev | ||
AlarmName: | ||
!Sub | ||
- 5XX rate from ${ApiName} | ||
- { ApiName: !FindInMap [StageMap, !Ref Stage, ApiName] } | ||
ComparisonOperator: GreaterThanThreshold | ||
Dimensions: | ||
- Name: ApiName | ||
Value: !FindInMap [StageMap, !Ref Stage, ApiName] | ||
- Name: Stage | ||
Value: !Sub ${Stage} | ||
EvaluationPeriods: 1 | ||
MetricName: 5XXError | ||
Namespace: AWS/ApiGateway | ||
Period: 3600 | ||
Statistic: Sum | ||
Threshold: 5 | ||
TreatMissingData: notBreaching |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
stacks: | ||
- membership | ||
regions: | ||
- eu-west-1 | ||
deployments: | ||
|
||
cfn: | ||
type: cloud-formation | ||
app: metric-push-api | ||
parameters: | ||
templatePath: cfn.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
log = . | ||
log4j.rootLogger = INFO, LAMBDA | ||
|
||
# Define the LAMBDA Appender | ||
log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender | ||
log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %l - %m%n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.