Code Monkey home page Code Monkey logo

arnparse's Introduction

arnparse

Parse ARNs using Python

Build Status

Motivation

Sometimes, you want to parse an Amazon Resource Name (ARN) into its components to get some useful information from the ARN (e.g. AWS region, account ID, etc).

You can find documentation on ARNs and their components here: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

Installation

pip install arnparse

Examples

S3 Object

from arnparse import arnparse

arn = arnparse('arn:aws:s3:::my_corporate_bucket/exampleobject.png')

assert arn.partition == 'aws'
assert arn.service == 's3'
assert arn.region is None
assert arn.account_id is None
assert arn.resource_type is None
assert arn.resource == 'my_corporate_bucket/exampleobject.png'

VPC

from arnparse import arnparse

arn = arnparse('arn:aws:ec2:us-east-1:123456789012:vpc/vpc-fd580e98')

assert arn.partition == 'aws'
assert arn.service == 'ec2'
assert arn.region == 'us-east-1'
assert arn.account_id == '123456789012'
assert arn.resource_type == 'vpc'
assert arn.resource == 'vpc-fd580e98'

CloudWatch Alarm

from arnparse import arnparse

arn = arnparse('arn:aws:cloudwatch:us-east-1:123456789012:alarm:MyAlarmName')

assert arn.partition == 'aws'
assert arn.service == 'cloudwatch'
assert arn.region == 'us-east-1'
assert arn.account_id == '123456789012'
assert arn.resource_type == 'alarm'
assert arn.resource == 'MyAlarmName'

SNS Topic

from arnparse import arnparse

arn = arnparse('arn:aws:sns:*:123456789012:my_corporate_topic')

assert arn.partition == 'aws'
assert arn.service == 'sns'
assert arn.region == '*'
assert arn.account_id == '123456789012'
assert arn.resource_type is None
assert arn.resource == 'my_corporate_topic'

API Gateway

from arnparse import arnparse

arn = arnparse('arn:aws:apigateway:us-east-1::a123456789012bc3de45678901f23a45:/test/mydemoresource/*')

assert arn.partition == 'aws'
assert arn.service == 'apigateway'
assert arn.region == 'us-east-1'
assert arn.account_id is None
assert arn.resource_type is None
assert arn.resource == 'a123456789012bc3de45678901f23a45:/test/mydemoresource/*'

arnparse's People

Contributors

spg avatar

Watchers

 avatar  avatar

Forkers

savobit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.