Amazon-SES
view release on metacpan or search on metacpan
t/iam-role.t~ view on Meta::CPAN
use strict;
use warnings;
use Test::Modern -internet;
use MIME::Entity;
use LWP::UserAgent;
use Amazon::SES;
use VM::EC2::Security::CredentialCache;
BEGIN {
# Try to get our credentials if it fails just skip these tests.
my $creds;
eval {
alarm(10);
$creds = VM::EC2::Security::CredentialCache->get();
};
if ($@ || !defined($creds)) {
$ENV{NO_CREDS} = 1;
}
}
SKIP: {
skip( "Environmental variables are not set or not on an EC2 instance with an IAM role", 25)
unless ($ENV{AWS_SES_IDENTITY} && !$ENV{NO_CREDS});
my $ses = object_ok(
sub {
return Amazon::SES->new(
use_iam_role => 1,
from => $ENV{AWS_SES_IDENTITY},
region => 'us-east-1'
);
},
'$ses',
isa => [qw(Amazon::SES)],
can => [qw(call send verify_email delete_domain delete_email delete_identity list_emails list_domains get_quota get_statistics send_mime get_dkim_attributes region access_key secret_key use_iam_role)],
clean => 1,
);
is($ses->region, 'us-east-1', "Region is: us-east-1");
my $r;
# Test that sending here generates an error code.
########## PLAIN
$r = $ses->send(
from => $ENV{AWS_SES_IDENTITY} . 'asdfasdfasdf',
to => 'suppressionlist@simulator.amazonses.com',
subject => "Hello world from AWS SES",
body => "Hello again",
body_html => "<h1>Салом Шоҳ</h1>",
);
#diag("send(): ", $r->result_as_json);
ok( $r->is_error, $r->error_message );
ok( $r->request_id, $r->request_id );
ok( $r->error_type, $r->error_type );
ok( $r->http_code == 400, 'code: ' . $r->http_code );
ok( $r->error_code, $r->error_code );
ok( !$r->message_id, "Message ID does not exist" );
ok( $r->result, "Result set exists even for error" );
################# MIME
my $msg = MIME::Entity->build(
From => $ENV{AWS_SES_IDENTITY},
To => 'success@simulator.amazonses.com',
Subject => 'MIME msg from AWS SES',
Data => "<h1>Hello world from AWS SES</h1>",
Type => 'text/html'
( run in 0.716 second using v1.01-cache-2.11-cpan-40ba7b3775d )