| Copyright | (C) 2020-2021 Bellroy Pty Ltd |
|---|---|
| License | BSD-3-Clause |
| Maintainer | Bellroy Tech Team <haskell@bellroy.com> |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
| Extensions |
|
Network.AWS.ARN
Contents
Description
Provides a type representing Amazon Resource Names (ARNs), and parsing/unparsing functions for them. The provided optics make it very convenient to rewrite parts of ARNs.
Example
API Gateway Lambda Authorizers are given the ARN of the requested endpoint and method, and are expected to respond with an IAM Policy Document. It is sometimes useful to manipulate the given ARN when describing which resources to authorize.
Here, we generalize authorizerSampleARN to cover every method of
every endpoint in the stage:
-- Returns "arn:aws:execute-api:us-east-1:123456789012:my-spiffy-api/stage/*" let authorizerSampleARN = "arn:aws:execute-api:us-east-1:123456789012:my-spiffy-api/stage/GET/some/deep/path" in over (_ARN.arnResource.slashes) (\parts -> take 2 parts ++ ["*"]) authorizerSampleARN
Synopsis
- data ARN r = ARN {
- _arnPartition :: Text
- _arnService :: Text
- _arnRegion :: Text
- _arnAccount :: Text
- _arnResource :: r
- toARN :: Text -> Maybe (ARN Text)
- fromARN :: ARN Text -> Text
- _ARN :: Prism' Text (ARN Text)
- arnPartition :: forall r. Lens' (ARN r) Text
- arnService :: forall r. Lens' (ARN r) Text
- arnRegion :: forall r. Lens' (ARN r) Text
- arnAccount :: forall r. Lens' (ARN r) Text
- arnResource :: forall r r. Lens (ARN r) (ARN r) r r
- colons :: Iso' Text [Text]
- slashes :: Iso' Text [Text]
Documentation
A parsed ARN. Either use the _ARN Prism', or the toARN and
fromARN functions to convert . The
Text <-> ARN_arnResource part of an ARN will often contain colon- or
slash-separated parts which precisely identify some resource. If
there is no service-specific module (see below), the colons and
slashes s in this module can pick apart the
Iso'_arnResource field.
Service-Specific Modules
Modules like Network.AWS.ARN.Lambda provide types to parse the resource part of an ARN into something more specific:
-- Remark: Lambda._Function ::Prism'TextLambda.Function -- Returns: Just "the-coolest-function-ever" let functionARN = "arn:aws:lambda:us-east-1:123456789012:function:the-coolest-function-ever:Alias" in functionARN ^? _ARN . arnResource . Lambda._Function . Lambda.fName
You can also use ARN's Traversable instance and
below to create Prism's that indicate their
resource type in ARN's type variable:
_ARN.belowLambda._Function ::Prism'Text(ARNLambda.Function)
Constructors
| ARN | |
Fields
| |
Instances
ARN Optics
Utility Optics
colons :: Iso' Text [Text] Source #
Split a Text into colon-separated parts.
This is not truly a lawful Iso', but it is useful. The Iso'
laws are violated for lists whose members contain ::
>>>[":"] ^. from colons . colons["",""]
The laws are also violated on empty lists:
>>>[] ^. from colons . colons[""]
However, it is still a useful tool:
>>>"foo:bar:baz" & colons . ix 1 .~ "quux""foo:quux:baz"