Skip to content

Commit b1d635e

Browse files
Add lambda inventory (#142)
Co-authored-by: erikpeteaws <[email protected]>
1 parent e8dafe2 commit b1d635e

File tree

6 files changed

+125
-10
lines changed

6 files changed

+125
-10
lines changed

data-collection/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ List of modules and objects collected:
2626
| `trusted-advisor` | AWS Trusted Advisor | Linked Account | Requires Enterpriso or OnRamp Support Level |
2727
| `cost-explorer-cost-anomaly` | AWS Anomalies | Management Account | |
2828
| `cost-explorer-rightsizing` | AWS Cost Explorer | Management Account | DEPRECATED. Please use `cost-optimization-hub` |
29-
| `inventory` | Various services | Linked Account | Collects `Amazon OpenSearch Domains`, `Amazon ElastiCache Clusters`, `RDS DB Instances`, `EBS Volumes`, `AMI`, `EC2 Instances`, `EBS Snapshot`, `RDS Snapshot` |
30-
| `pricing` | Various services | N/A | Collects pricing for `Amazon RDS`, `Amazon EC2`, `Amazon ElastiCache`, `Amazon OpenSearch`, `AWS Compute Savings Plan` |
29+
| `inventory` | Various services | Linked Account | Collects `Amazon OpenSearch Domains`, `Amazon ElastiCache Clusters`, `RDS DB Instances`, `EBS Volumes`, `AMI`, `EC2 Instances`, `EBS Snapshot`, `RDS Snapshot`, `Lambda` |
30+
| `pricing` | Various services | N/A | Collects pricing for `Amazon RDS`, `Amazon EC2`, `Amazon ElastiCache`, `AWS Lambda`, `Amazon OpenSearch`, `AWS Compute Savings Plan` |
3131
| `rds-usage` | Amazon RDS | Linked Account | Collects CloudWatch metrics for chargeback |
3232
| `transit-gateway` | AWS Transit Gateway | Linked Account | Collects CloudWatch metrics for chargeback |
3333
| `ecs-chargeback` | Amazon ECS | Linked Account | |

data-collection/deploy/deploy-in-linked-account.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Resources:
197197
- "elasticache:DescribeCacheClusters"
198198
- "eks:ListClusters"
199199
- "eks:DescribeCluster"
200+
- "lambda:ListFunctions"
200201
Resource: "*" ## Policy is used for scanning of a wide range of resources
201202
Roles:
202203
- Ref: LambdaRole
@@ -272,4 +273,4 @@ Resources:
272273
cfn_nag:
273274
rules_to_suppress:
274275
- id: W12
275-
reason: "Policy is used for scanning of a wide range of resources"
276+
reason: "Policy is used for scanning of a wide range of resources"

data-collection/deploy/module-inventory.yaml

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Parameters:
5656
Description: ARN of a Lambda for Managing GlueTable
5757
AwsObjects:
5858
Type: CommaDelimitedList
59-
Default: OpensearchDomains, ElasticacheClusters, RdsDbInstances, EBS, AMI, Snapshot, Ec2Instances, VpcInstances, RdsDbSnapshots, EKSClusters
59+
Default: OpensearchDomains, ElasticacheClusters, RdsDbInstances, EBS, AMI, Snapshot, Ec2Instances, VpcInstances, RdsDbSnapshots, EKSClusters, AWSLambda
6060
Description: Services for pulling price data
6161

6262
Mappings:
@@ -789,7 +789,77 @@ Mappings:
789789
paths: Arn,Name,CreatedAt,Version,accountid,collection_date,region
790790
SerializationLibrary: org.openx.data.jsonserde.JsonSerDe
791791
TableType: EXTERNAL_TABLE
792-
792+
AWSLambda:
793+
path: lambda
794+
table:
795+
- Name: inventory_lambda_data
796+
PartitionKeys:
797+
- Name: payer_id
798+
Type: string
799+
- Name: year
800+
Type: string
801+
- Name: month
802+
Type: string
803+
- Name: day
804+
Type: string
805+
StorageDescriptor:
806+
Columns:
807+
- Name: functionname
808+
Type: string
809+
- Name: functionarn
810+
Type: string
811+
- Name: runtime
812+
Type: string
813+
- Name: role
814+
Type: string
815+
- Name: handler
816+
Type: string
817+
- Name: codesize
818+
Type: int
819+
- Name: description
820+
Type: string
821+
- Name: timeout
822+
Type: int
823+
- Name: memorysize
824+
Type: int
825+
- Name: lastmodified
826+
Type: string
827+
- Name: codesha256
828+
Type: string
829+
- Name: version
830+
Type: string
831+
- Name: tracingconfig
832+
Type: struct<mode:string>
833+
- Name: revisionid
834+
Type: string
835+
- Name: packagetype
836+
Type: string
837+
- Name: architectures
838+
Type: array<string>
839+
- Name: ephemeralstorage
840+
Type: struct<size:int>
841+
- Name: snapstart
842+
Type: struct<applyon:string,optimizationstatus:string>
843+
- Name: loggingconfig
844+
Type: struct<logformat:string,loggroup:string>
845+
- Name: accountid
846+
Type: string
847+
- Name: collection_date
848+
Type: string
849+
- Name: region
850+
Type: string
851+
- Name: layers
852+
Type: array<struct<arn:string,codesize:int>>
853+
- Name: vpcconfig
854+
Type: struct<subnetids:array<string>,securitygroupids:array<string>,vpcid:string,ipv6allowedfordualstack:boolean>
855+
InputFormat: org.apache.hadoop.mapred.TextInputFormat
856+
Location: !Sub s3://${DestinationBucket}/inventory/inventory-lambda-data/
857+
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
858+
SerdeInfo:
859+
Parameters:
860+
paths: functionname, functionarn, runtime, role, handler, codesize, dedscription, timeout, memorysize, lastmodified, codesha256, version, tracingconfig, revisionid, packagetype, architectures, ephemeralstorage, snapstart, loggingconfig, accountid, collection_date, region, layers, vpcconfig
861+
SerializationLibrary: org.openx.data.jsonserde.JsonSerDe
862+
TableType: EXTERNAL_TABLE
793863

794864
Resources:
795865
LambdaRole:
@@ -1005,6 +1075,12 @@ Resources:
10051075
service='ec2',
10061076
function_name='describe_vpcs'
10071077
),
1078+
'lambda' : partial(
1079+
paginated_scan,
1080+
service='lambda',
1081+
function_name='list_functions',
1082+
obj_name='Functions[*]'
1083+
),
10081084
'eks': eks_clusters_scan
10091085
}
10101086

data-collection/deploy/module-pricing.yaml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Parameters:
3535
Description: Arn of lambda for Analytics
3636
AwsServices:
3737
Type: CommaDelimitedList
38-
Default: AmazonRDS, AmazonEC2, AmazonElastiCache, AmazonES, AWSComputeSavingsPlan, RegionNames
38+
Default: AmazonRDS, AmazonEC2, AmazonElastiCache, AmazonES, AWSComputeSavingsPlan, RegionNames, AWSLambda
3939
Description: Services for pulling price data
4040
CodeBucket:
4141
Type: String
@@ -317,6 +317,34 @@ Mappings:
317317
- { Type: string, Name: regionname }
318318
- { Type: string, Name: endpoint }
319319
- { Type: string, Name: protocol }
320+
AWSLambda:
321+
path: lambda
322+
partition:
323+
- { Name: region, Type: string }
324+
fields:
325+
- { Type: string, Name: sku }
326+
- { Type: string, Name: offertermcode }
327+
- { Type: string, Name: ratecode }
328+
- { Type: string, Name: termtype }
329+
- { Type: string, Name: pricedescription }
330+
- { Type: string, Name: effectivedate }
331+
- { Type: string, Name: endingrange }
332+
- { Type: bigint, Name: startingrange }
333+
- { Type: string, Name: endingrange }
334+
- { Type: string, Name: unit }
335+
- { Type: double, Name: priceperunit }
336+
- { Type: string, Name: currency }
337+
- { Type: string, Name: relatedto }
338+
- { Type: string, Name: product family }
339+
- { Type: string, Name: servicecode }
340+
- { Type: string, Name: location }
341+
- { Type: string, Name: location type }
342+
- { Type: string, Name: group }
343+
- { Type: string, Name: group description }
344+
- { Type: string, Name: usagetype }
345+
- { Type: string, Name: operation }
346+
- { Type: string, Name: region code }
347+
- { Type: string, Name: servicename }
320348
RDSGraviton:
321349
path: rdsgraviton
322350
partition:
@@ -695,4 +723,4 @@ Resources:
695723
Type: Custom::LambdaAnalyticsExecutor
696724
Properties:
697725
ServiceToken: !Ref LambdaAnalyticsARN
698-
Name: !Ref CFDataName
726+
Name: !Ref CFDataName

data-collection/test/test_from_scratch.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ def test_inventory_vpc_data(athena):
8383

8484
def test_inventory_rds_snaphot_data(athena):
8585
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."inventory_rds_db_snapshots_data" LIMIT 10;')
86-
assert len(data) > 0, 'inventory_vpc_data is empty'
86+
assert len(data) > 0, 'inventory_rds_db_snapshots_data is empty'
87+
88+
def test_inventory_lambda_data(athena):
89+
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."inventory_lambda_data" LIMIT 10;')
90+
assert len(data) > 0, 'inventory_lambda_data is empty'
8791

8892
def test_rds_usage_data(athena):
8993
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."rds_usage_data" LIMIT 10;')
@@ -137,6 +141,10 @@ def test_pricing_rds_data(athena):
137141
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."pricing_rds_data" LIMIT 10;')
138142
assert len(data) > 0, 'pricing_rds_data is empty'
139143

144+
def test_pricing_lambda_data(athena):
145+
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."pricing_lambda_data" LIMIT 10;')
146+
assert len(data) > 0, 'pricing_awslambda_data is empty'
147+
140148
def test_pricing_regionnames_data(athena):
141149
data = athena_query(athena=athena, sql_query='SELECT * FROM "optimization_data"."pricing_regionnames_data" LIMIT 10;')
142150
assert len(data) > 0, 'pricing_regionnames_data is empty'
@@ -164,4 +172,4 @@ def test_health_events_data(athena):
164172

165173

166174
if __name__ == '__main__':
167-
pytest.main()
175+
pytest.main()

data-collection/test/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def trigger_update(account_id):
344344
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}inventory-Ec2Instances-StateMachine',
345345
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}inventory-VpcInstances-StateMachine',
346346
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}inventory-RdsDbSnapshots-StateMachine',
347+
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}inventory-AWSLambda-StateMachine',
347348
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}rds-usage-StateMachine',
348349
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}transit-gateway-StateMachine',
349350
f'arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}trusted-advisor-StateMachine',
@@ -356,6 +357,7 @@ def trigger_update(account_id):
356357
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}pricing-AmazonElastiCache-StateMachine",
357358
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}pricing-AmazonES-StateMachine",
358359
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}pricing-AWSComputeSavingsPlan-StateMachine",
360+
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}pricing-AWSLambda-StateMachine",
359361
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}pricing-RegionNames-StateMachine",
360362
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}backup-CopyJobs-StateMachine",
361363
f"arn:aws:states:{region}:{account_id}:stateMachine:{PREFIX}backup-RestoreJobs-StateMachine",
@@ -414,4 +416,4 @@ def cleanup_stacks(cloudformation, account_id, s3, s3client, athena, glue):
414416
def prepare_stacks(cloudformation, account_id, org_unit_id, s3, s3client, bucket):
415417
initial_deploy_stacks(cloudformation=cloudformation, account_id=account_id, org_unit_id=org_unit_id, bucket=bucket)
416418
clean_bucket(s3=s3, s3client=s3client, account_id=account_id, full=False)
417-
trigger_update(account_id=account_id)
419+
trigger_update(account_id=account_id)

0 commit comments

Comments
 (0)