by macintux · 6y ago · 0 comments
1 Retrieve all layers with list_layers and index them by ARN
2 Retrieve all function metadata
3 For each function metadata item, extract all layer version ARNs
4 For each layer version ARN, call get_layer_version_by_arn
5 Extract the layer ARN from that result
6 Use that layer ARN to retrieve the name from the data we retrieved in step 1
If you just need the Layer Arn to call other APIs:
a) You could eliminate steps 1 and 6, and use the Layer Arn value from 5 to call APIs that require a layer name.
b) Alternatively, you could yourself chop off the version number from the Layer Version Arn string(s) in step 4, and skip the GetLayerVersionByArn call in step 5 all together.
If you explicitly require the name, not the Layer Arn:
c) You could parse it right out of the Layer Version Arn yourself.
When it comes to doing your own string manipulation for (b) or (c), there are many ways to skin a cat ... but you could use regex (the pattern is in the API documentation), or split on colons and index the second to last element in the array.
Is it useful to return the Layer Name in more APIs? What is your use-case?
I am reluctant to treat ARNs as anything but opaque blobs; I do so when necessary, but I know their format has changed in the past, and the lack of a central resource to track breaking changes across AWS means that we would likely not know that the ARN format is changing until our tools break.
I appreciate the ideas, however, and I'll look more closely at my flow to see what shortcuts I can live with.