![]() |
![]()
| ![]() |
![]()
NAMEPaws - A Perl SDK for AWS (Amazon Web Services) APIsSYNOPSISuse Paws; my $obj = Paws->service('...'); my $res = $obj->MethodCall(Arg1 => $val1, Arg2 => $val2); print $res->AttributeFromResult; DESCRIPTIONPaws is an attempt to develop an always up-to-date SDK that covers all possible AWS services.STATUSPlease consider the SDK is beta quality. The intention of publishing to CPAN is having the community find the SDK, try it, give feedback, etc. Some services are still not working, and some heavy refactoring will still be done to the internals. The external interface to SDK users will try to be kept stable, and changes to it should be notified via ChangeLogSUPPORTED SERVICESPlease take a look at classes in the Paws::XXX namespaceSERVICES CLASSESEach service in AWS (EC2, CloudFormation, SQS, SNS, etc) has a service class. The service class represents the properties that a web service has (how to call it, what methods it has, how to authenticate, etc). When a service class is instantiated with the right properties (region, if needed, credentials, caller, etc), it will be able to make calls to the service.Service classes are obtained through my $service_class = Paws->class_for_service('Service'); my $service_object = $service_class->new(region => '...', caller => ...) Although they are seldom needed. 99% of the time you want service objects directly obtained with the ->service method (read next section) since you have to write less code. SERVICE OBJECTSEach Service Object represents the ability to call methods on a service endpoint. Those endpoints are either global, or bound to a region depending on the service. Also, each object can be customized with a credential provider, that tells the object where to obtain credentials for the call (you can get them from the environment, from the filesystem, from the AWS Instance Profile, STS, etc.To obtain a service object, call the "->service" method use Paws; my $service = Paws->service('Service'); You can pass extra parameters if the service is bound to a region: my $service = Paws->service('Service', region => 'us-east-1'); These parameters are basically passed to the service class constructor AUTHENTICATIONService classes by default try to authenticate with a chained authenticator. The chained authenticator tries to first find credentials in your environment variables AWS_ACCESS_KEY and AWS_SECRET_KEY (note that AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are also scanned for compatibility with the official SDKs). Second, it will look for credentials in the default profile of the ~/.aws/credentials or the file in AWS_CONFIG_FILE env variable (an ini-formatted file). Last, if no environment variables are found, then a call to retrieve Role credentials is done. If your instance is running on an AWS instance, and has a Role assigned, the SDK will automatically retrieve credentials to call any services that the instances Role permits.Please never burn credentials into your code. That's why the methods for passing an explicit access key and secret key are not documented. So, instantiating a service with my $ec2 = Paws->service('EC2', region => 'eu-west-1'); we get an service object that will try to authenticate with environment, credential file, or an instance role. When instantiating a service object, you can also pass a custom credential provider: use Paws::Credential::STS; my $cred_provider = Paws::Credential::STS->new( Name => 'MyName', DurationSeconds => 900, Policy => '{"Version":"2012-10-17","Statement":[{"Effect": "Allow","Action":["ec2:DescribeInstances"],"Resource":"*"}]}' ); my $ec2 = Paws->service('EC2', credentials => $cred_provider, region => 'eu-west-1'); In this example we instance a service object that uses the STS service to create temporary credentials that only let the service object call DescribeInstances. Using Service objects (Calling APIs)Each API call is represented as a method call with the same name as the API call. The arguments to the call are passed as lists (named parameters) to the call. So, to call DescribeInstances on the EC2 service:my $result = $ec2->DescribeInstances; The DescribeInstances call has no required parameters, but if needed, we can pass them in (you can look them up in Paws::EC2 and see detail in Paws::EC2::DescribeInstances my $result = $ec2->DescribeInstances(MaxResults => 5); If the parameter is an Array: my $result = $ec2->DescribeInstances(InstanceIds => [ 'i-....' ]); If the parameter to be passed in is a complex value (an object) my $result = $ec2->DescribeInstances(Filters => [ { Name => '', Value => '' } ]) RETURN VALUESThe AWS APIs return nested datastructures in various formats. The SDK converts these datastructures into objects that can then be used as wanted.my $private_dns = $result->Reservations->[0]->Instances->[0]->PrivateDnsName; CONFIGURATIONPaws instances have a configuration. The configuration is basically a specification of values that will be passed to the service method each time it's called# the credentials and the caller keys accept an instance or the name of a class as a # string (the class will be loaded and the constructor of that class will be automatically called my $paws1 = Paws->new(config => { credentials => MyCredProvider->new, region => 'eu-west-1' }); my $paws2 = Paws->new(config => { caller => 'MyCustomCaller' }); # EC2 service with MyCredProvider in eu-west-1 my $ec2 = $paws1->service('EC2'); # DynamoDB service with MyCustomCaller in us-east-1. region is needed because it's not in the config my $ddb = $paws2->service('DynamoDB', region => 'us-east-1'); # DynamoDB in eu-west-1 with MyCredProvider my $other_ddb = $paws1->service('DynamoDB'); The attributes that can be configured are: credentials Accepts a string which value is the name of a class, or an already instantiated object. If a string is passed, the class will be loaded, and the constructor called (without parameters). Also, the resulting instance or the already instantiated object has to have the Paws::Credential role. caller Accepts a string which value is the name of a class, or an already instantiated object. If a string is passed, the class will be loaded, and the constructor called (without parameters). Also, the resulting instance or the already instantiated object has to have the Paws::Net::CallerRole role. region A string representing the region that service objects will be instantiated with. Default value is undefined, meaning that you will have to specify the desired region every time you call the service method. PluggabilityCredential Provider PluggabilityCredential classes need to have the Role Paws::Credential applied. This obliges them to implement access_key, secret_key and session_token methods. The obtention of this data can be customized to be retrieved whereever the developer considers useful (files, environment, other services, etc). Take a look at the Paws::Credential::XXXX namespace to find already implemented credential providers.The credential objects' access_key, secret_key and session_token methods will be called each time an API call has to be signed. Caller PluggabilityCaller classes need to have the Role Paws::Net::CallerRole applied. This obliges them to implement the do_call method. Tests use this interface to mock calls and responses to the APIs (without using the network). If you want to use Asyncronous IO, take a look at the Paws::Net::MojoAsyncCaller in the examples directory.The caller instance is responsable for doing the network Input/Output with some type of HTTP request library, and returning the Result from the API. AUTHORJose Luis Martinez CPAN ID: JLMARTIN CAPSiDE jlmartinez@capside.com SEE ALSO<http://aws.amazon.com/documentation/><https://github.com/pplu/aws-sdk-perl> BUGS and CONTRIBUTIONSThe source code is located here: https://github.com/pplu/aws-sdk-perlPlease report bugs to: https://github.com/pplu/aws-sdk-perl/issues COPYRIGHT and LICENSECopyright (c) 2015 by Jose Luis Martinez TorresThis code is distributed under the GNU Lesser General Public License, Version 3. The full text of the license can be found in the LICENSE file included with this module.
|