The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::AWS - AWS via Mojolicious

SYNOPSIS

  # Mojolicious
  $self->plugin('Mojolicious::Plugin::AWS');

  # Mojolicious::Lite
  plugin 'Mojolicious::Plugin::AWS';

  $c->sns_publish(
      region     => 'us-east-2',
      topic      => $topic_arn,
      subject    => 'my subject',
      message    => {default => 'my message'},
      access_key => $access_key,
      secret     => $secret_key
  )->then(
    sub {
        my $tx = shift;
        say $tx->res->json('/PublishResponse/PublishResult/MessageId');
    }
  );

DESCRIPTION

Mojolicious::Plugin::AWS is a Mojolicious plugin for accessing Amazon Web Service resources. This module is ALPHA QUALITY meaning its interface is likely to change in backward-incompatible ways. See the "CAVEATS" section below.

CAVEATS

This module is alpha quality. This means that its interface will likely change in backward-incompatible ways, that its performance is unreliable, that the example code snippets may be wrong or out of date, and that the code quality is only meant as a proof-of-concept. Its use is discouraged except for experimental, non-production deployments.

HELPERS

Mojolicious::Plugin::AWS implements the following helpers.

sns_publish

  $c->sns_publish(
      region     => $aws_region,
      access_key => $access_key,
      secret_key => $secret_key,
      topic      => $topic_arn,
      subject    => 'Automatic Message',
      message    => {
          default => 'default message',
          https   => 'this is sent to your HTTPS endpoint'
      }
  )->then(
      sub {
          my $tx = shift;
          say STDERR "Response: " . $tx->res->body;
      }
  )->wait;

Returns a Mojo::Promise object that contains the results of the AWS SNS Publish command:

  use Data::Dumper;
  say Dumper $tx->res->json;

  {
    'PublishResponse' => {
      'PublishResult' => {
        'MessageId' => '5d9ab65c-0363-5a41-dba1-f1bb241d9132',
        'SequenceNumber' => undef
      },
      'ResponseMetadata' => {
        'RequestId' => '3b8c6c31-a7eb-b5d6-58d4-df0fc3b80192'
      }
    }
  }

s3_retrieve

  $c->s3_retrieve(
      region     => $aws_region,
      access_key => $access_key,
      secret_key => $secret_key,
      url        => Mojo::URL->new($s3_url),
  )->then(
      sub {
          my $tx = shift;
          Mojo::File->new('my-file.jpg')->spurt($tx->res->body);
      }
  )->catch(
      sub {
          my $err = shift;
          warn "Unable to retrieve object: $err";
      }
  )->wait;

Returns a Mojo::Promise object that contains the results of the AWS S3 Retrieve command, usually the object/file you requested.

METHODS

Mojolicious::Plugin::AWS inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register(Mojolicious->new);

Register plugin in Mojolicious application.

AUTHOR

Scott Wiersdorf, <scott@perlcode.org>

SPONSORS

COPYRIGHT AND LICENSE

Copyright (C) 2019, Scott Wiersdorf.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

Mojolicious, Mojolicious::Guides, https://mojolicious.org.