Skip to content

Commit d2936d6

Browse files
committed
feat: Add cloudfront connection to cloudwatch service
1 parent fd4c563 commit d2936d6

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
8080
| cloud9 | |
8181
| cloudformationStack | cloudformationStack, iamRole, sns |
8282
| cloudformationStackSet | iamRole |
83-
| cloudfront | elb, s3 |
83+
| cloudfront | cloudwatch, elb, s3 |
8484
| cloudtrail | cloudwatch, cloudwatchLog, kms, s3, sns |
85-
| cloudwatch | cloudtrail, cloudwatchLog, sns |
85+
| cloudwatch | cloudfront, cloudtrail, cloudwatchLog, sns |
8686
| cloudwatchLog | cloudtrail, cloudwatch, ecsCluster, elasticSearchDomain, kms, managedAirflow, rdsDbInstance |
8787
| codebuild | iamRole, kms, vpc, securityGroup, subnet |
8888
| cognitoIdentityPool | iamRole, iamOpenIdConnectProvider, iamSamlProvider, elasticSearchDomain |

src/services/cloudfront/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type awsCloudfront implements awsBaseService @key(fields: "id") {
2121
s3: [awsS3] @hasInverse(field: cloudfrontDistributions)
2222
tags: [awsRawTag]
2323
webAcl: [awsWafV2WebAcl] @hasInverse(field: cloudfront)
24+
cloudwatch: [awsCloudwatch] @hasInverse(field: cloudfront)
2425
}
2526

2627
type awsCloudfrontOriginData {

src/services/cloudwatch/connections.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ServiceConnection } from '@cloudgraph/sdk'
22
import { isEmpty } from 'lodash'
33
import { RawAwsCloudwatch } from './data'
4+
import { RawAwsCloudfront } from '../cloudfront/data'
45
import services from '../../enums/services'
6+
import { globalRegionName } from '../../enums/regions'
57

68
export default ({
79
service: cloudwatch,
@@ -15,7 +17,11 @@ export default ({
1517
}): {
1618
[property: string]: ServiceConnection[]
1719
} => {
18-
const { AlarmName: id, AlarmActions: alarmActions } = cloudwatch
20+
const {
21+
AlarmName: id,
22+
AlarmActions: alarmActions,
23+
Dimensions: dimensions,
24+
} = cloudwatch
1925
const connections: ServiceConnection[] = []
2026

2127
/**
@@ -40,6 +46,33 @@ export default ({
4046
}
4147
}
4248

49+
/**
50+
* Find Cloudfront
51+
* related to the cloudwatch
52+
*/
53+
const cloudfronts = data.find(({ name }) => name === services.cloudfront)
54+
if (cloudfronts?.data?.[globalRegionName]) {
55+
const cloudfrontsInRegion: RawAwsCloudfront[] = cloudfronts.data[
56+
globalRegionName
57+
].filter(({ summary: { Id: cloudfrontId } }: RawAwsCloudfront) =>
58+
dimensions?.some(d => d.Value === cloudfrontId)
59+
)
60+
61+
if (!isEmpty(cloudfrontsInRegion)) {
62+
for (const cf of cloudfrontsInRegion) {
63+
const {
64+
summary: { Id: cloudfrontId },
65+
}: RawAwsCloudfront = cf
66+
connections.push({
67+
id: cloudfrontId,
68+
resourceType: services.cloudfront,
69+
relation: 'child',
70+
field: 'cloudfront',
71+
})
72+
}
73+
}
74+
}
75+
4376
const result = {
4477
[id]: connections,
4578
}

src/services/cloudwatch/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type awsCloudwatch implements awsBaseService @key(fields: "arn") {
1414
cloudwatchLog: [awsCloudwatchLog] @hasInverse(field: cloudwatch)
1515
sns: [awsSns] @hasInverse(field: cloudwatch)
1616
cloudtrail: [awsCloudtrail] @hasInverse(field: cloudwatch)
17+
cloudfront: [awsCloudfront] @hasInverse(field: cloudwatch)
1718
}
1819

1920
type awsCloudwatchDimensions

src/types/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ export type AwsCloudFormationStackSetParameter = {
741741

742742
export type AwsCloudfront = AwsBaseService & {
743743
callerReference?: Maybe<Scalars['String']>;
744+
cloudwatch?: Maybe<Array<Maybe<AwsCloudwatch>>>;
744745
customErrorResponses?: Maybe<Array<Maybe<AwsCloudfrontCustomErrorResponse>>>;
745746
defaultCacheBehavior?: Maybe<AwsCloudfrontCacheBehavior>;
746747
defaultRootObject?: Maybe<Scalars['String']>;
@@ -896,6 +897,7 @@ export type AwsCloudtrailStatus = {
896897
export type AwsCloudwatch = AwsBaseService & {
897898
actions?: Maybe<Array<Maybe<Scalars['String']>>>;
898899
actionsEnabled?: Maybe<Scalars['String']>;
900+
cloudfront?: Maybe<Array<Maybe<AwsCloudfront>>>;
899901
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
900902
cloudwatchLog?: Maybe<Array<Maybe<AwsCloudwatchLog>>>;
901903
comparisonOperator?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)