In this guide we're going to write a CloudWanderer dependent resource definition for lambda layer versions.
A CloudWanderer dependent resource is a specific type of Boto3 resource.
CloudWanderer dependent resources are resources which depend on their parent for their identity. A resource is a dependent resource in CloudWanderer terms if you must supply the ID of its parent in order to fetch it (e.g. IAM Role inline policies).
In our case lambda layer versions are dependent resources because you cannot fetch metadata about them from the AWS API without supplying the name of the layer of which they are a version.
Note
This guide assumes you have read the example_resource
guide as a pre-requisite. As it has a lot more detail on some of the steps outlined here. Look to that page for further clarification if need be.
$ aws lambda list-layer-versions --layer-name test-layer
{
"LayerVersions": [
{
"LayerVersionArn": "arn:aws:lambda:eu-west-1:123456789012:layer:test-layer:1",
"Version": 1,
"Description": "This is a test layer!",
"CreatedDate": "2020-10-17T13:18:00.303+0000",
"CompatibleRuntimes": [
"nodejs10.x"
]
}
]
}
Dependent resources are always discovered alongside their parents, so our tests for lambda layer versions will fit nicely alongside the tests for lambda layers.
{
"service": "lambda",
"mockData": {
"get_paginator.side_effect": [
{
"paginate.return_value": [
{
"Layers": [
{
"LayerName": "test-layer",
"LayerArn": "arn:aws:lambda:eu-west-1:123456789012:layer:test-layer",
"LatestMatchingVersion": {
"LayerVersionArn": "arn:aws:lambda:eu-west-1:123456789012:layer:test-layer:1",
"Version": 1,
"Description": "This is a test layer!",
"CreatedDate": "2020-10-17T13:18:00.303+0000",
"CompatibleRuntimes": [
"nodejs10.x"
]
}
}
]
}
]
},
{
"paginate.return_value": [
{
"LayerVersions": [
{
"LayerVersionArn": "arn:aws:lambda:eu-west-1:123456789012:layer:test-layer:1",
"Version": 1,
"Description": "This is a test layer!",
"CreatedDate": "2020-10-17T13:18:00.303+0000",
"CompatibleRuntimes": [
"nodejs10.x"
]
}
]
}
]
}
]
}
}
We've added our test payload as a second value in the existing mockData.get_paginator.side_effect
list. It is the second in the list because dependent resources are discovered _after top level resources.
..tip:
We'll also need to add another dict to the end of the ``expectedResults`` key, but like before you can populate
that with the results the failing test spits out when you run it at the end!
Visit Botocore's specification data on GitHub and open the latest service-2.json
for your service.
We're here following much the same process as in example_resource
. We're going to add a LambdaLayerVersion
resource specification to the aws_interface/resource_definitions/lambda/2015-03-31/resource-1.json
file.
We're following our ListLayerVersions
through its return of ListLayerVersionsResponse
to its shape of LayerVersionsList
to its member of LayerVersionsListItem
. Along the way we've identified the
- Collection Request Operation (
ListLayerVersions
) - Resource Shape (
LayerVersionsListItem
) - Identifiers (
LayerName
andVersion
)
Dependent resources always have two identifiers, one is the identifier of their parent, and the other is their identifier. In CloudWanderer's definition this is what makes them a dependent resource, that they do not have an independent identity without their parent.
[
{
"target": "LayerName",
"source": "identifier",
"name": "LayerName"
},
{
"target": "Version",
"source": "response",
"path": "LayerVersions[].Version"
}
]
Top level resource request operations (e.g. ListLayers
) were pretty simple as they had no arguments. Dependent resources on the other hand need to supply the identity of their parent as an argument to whatever API method they're calling.
{
"operation": "ListLayerVersions",
"params": [
{
"target": "LayerName",
"source": "identifier",
"name": "LayerName"
}
]
}
This will take the LayerName
from the parent resource, and submit it as a parameter called LayerName
to the ListLayerVersions
API method.
In the resources
definiton we've added the highlighted lines.
You'll notice we've added the collection specification inside the Layer
resource instead of inside the service
as we did in example_resource
, this is what allows us to reference the LayerName
of the parent resource when we call ListLayerVersions
in our collection API call.
The service map is CloudWanderer's store for resource type metadata that does not fit into the Boto3 specification. It broadly follows the structure of Boto3's to try and keep things simple and consistent. For our new Layer resource we just need to ensure that the following exists in aws_interface/resource_definitions/lambda/2015-03-31/resources-cw-1.json
{
"service": {
"globalService": false,
"regionalResources": true
},
"resources": {
"Layer": {
"type": "baseResource"
},
"LayerVersion": {
"type": "dependentResource"
}
}
}
We added the LayerVersion
key to resources
to indicate that we've added a dependent resource whose parent resource type is Layer
. This allows CloudWanderer to determine the proper relationship between these resources and properly generate URNs.