Layer Name and Layer Arn (the Layer Version Arn without a version suffix) are interchangeable in APIs that require a Layer Name parameter. I understand that you're trying to extract the "LayerName" field returned in the API response in ListLayers, but you can do it more concisely.
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?
Sorry, been away from this for a while. This is for a dashboard (we have many accounts and not all stakeholders have permissions across all accounts, so we need ways to manage the information outside the web console).
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.
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