pplu / aws-sdk-perl

A community AWS SDK for Perl Programmers
Other
171 stars 94 forks source link

Creating a distribution fails on CloudFront #367

Open HexaCubist opened 4 years ago

HexaCubist commented 4 years ago

My goal is to create a basic CloudFront distribution using the Paws sdk, and as of yet I have been unable to get past an error 400 with the following configuration:

use Paws;
use Data::Printer;

my $cloudfront = Paws->service('CloudFront');

my $CreateDistributionResult = $cloudfront->CreateDistribution(
DistributionConfig => {
  CallerReference      => "1578211502",
  Origins => {
    Quantity => 1,
    Items => [{
      DomainName => "foo.s3-website-ap-southeast-2.amazonaws.com",
      Id => 'S3-Website-foo.s3-website-ap-southeast-2.amazonaws.com'}]
  },
  DefaultCacheBehavior => {
    ForwardedValues => {
      Cookies => {Forward => 'none'},
      QueryString => 0
    },
    TargetOriginId => 'S3-Website-foo.s3-website-ap-southeast-2.amazonaws.com',
    TrustedSigners => {
      Enabled  => 0,
      Quantity => 0
    },
    ViewerProtocolPolicy => 'redirect-to-https',
    MinTTL => 0
  },
  Comment              => "foo bar",
  Enabled => 1
  });

p $CreateDistributionResult;

The above is the complete set of only the required fields as defined in the api documentation here and here. However, when I run the above it crashes with the following:

[foo@bar~]# perl aws.pl
Paws::CloudFront is not stable / supported / entirely developed at /root/perl5/lib/perl5/Paws/CloudFront.pm line 2.
Bad Request

Trace begun at /root/perl5/lib/perl5/Paws/Net/RestXMLResponse.pm line 24
Paws::Net::RestXMLResponse::process('Paws::Net::RestXMLResponse=HASH(0x2f275b8)', 'Paws::CloudFront::CreateDistribution=HASH(0x2fbe6e0)', 'Paws::Net::APIResponse=HASH(0x30c0ec0)') called at /root/perl5/lib/perl5/Paws/Net/Caller.pm line 46
Paws::Net::Caller::caller_to_response('Paws::Net::Caller=HASH(0x16d7bb8)', 'Paws::CloudFront=HASH(0x2a615f8)', 'Paws::CloudFront::CreateDistribution=HASH(0x2fbe6e0)', 'Paws::Net::APIResponse=HASH(0x30c0ec0)') called at /root/perl5/lib/perl5/Paws/Net/RetryCallerRole.pm line 19
Paws::Net::RetryCallerRole::do_call('Paws::Net::Caller=HASH(0x16d7bb8)', 'Paws::CloudFront=HASH(0x2a615f8)', 'Paws::CloudFront::CreateDistribution=HASH(0x2fbe6e0)') called at /root/perl5/lib/perl5/Paws/CloudFront.pm line 49
Paws::CloudFront::CreateDistribution('Paws::CloudFront=HASH(0x2a615f8)', 'DistributionConfig', 'HASH(0x2f9c500)') called at aws.pl line 6

What is a correct minimal call that would work here?

byterock commented 4 years ago

At the Present moment None!

All of the AWS Rest APIs of Paws 0.41 are not stable only a few of the S3 calls work and none of the CloudFront Actions will work.

However I am nearing the end of the rather long process of getting them all working.

For more details have a look at the last of my PAWS reports

http://blogs.perl.org/mt/mt-search.fcgi?IncludeBlogs=2165&limit=20&search=PAWS

The latest one is on CloudFront.

I have not checked in the Cloudfront changesyet as I still have to a regression check to make sure I havn't broken anyting.

The branch I am working in is

https://github.com/byterock/aws-sdk-perl/tree/s3ObjectTagging

though I will most likely not check in the CloudFront fixes untill later today or tomorrow.

The mimimal creation call is great I will give it a try when I get back to work with CloudFront later today.

Cheers

HexaCubist commented 4 years ago

Bummer! Good to know though, I will keep an eye on that branch and will give it a test once you have something working.

Cheers!

byterock commented 4 years ago

As of a few mins ago I checked in a fully working CloudFront

on the same branch as above

You might have to change you boto to this branch as well

https://github.com/byterock/botocore/tree/s3-changes

I tested all the actions and the all work against a live AWS account.

They are a little tricky to play with a good start is to create a distribution first via the AWS AI then get its config using 'GetDistributionConfig' and then use that as a base to create other dists. That was the only way I could get it to work

Cheers and happy Couldfronting.

HexaCubist commented 4 years ago

Awesome! However - one problem: I'm super new to Perl and have lacked success in getting this version installed. After cloning it on the server I ran cpanm ., which took some time to think and returned the following:

...
[DZ] beginning to build Paws
[Prereqs::FromCPANfile] Parsing 'cpanfile' to extract prereqs
[DZ] writing Paws in Paws-0.41
[DZ] building archive with Archive::Tar; install Archive::Tar::Wrapper 0.15 or newer for improved speed
[DZ] writing archive to Paws-0.41.tar.gz
[DZ] built in Paws-0.41
carton exec -- prove t/
Can't find cpanfile.snapshot: Run `carton install` to build the snapshot file.
make: *** [test] Error 255
-> FAIL Installing . failed. See /root/.cpanm/work/1579153249.18071/build.log for details. Retry with --force to force install it.

What am I doing wrong here? I tried running carton install but that only served to make it crash at a different place.

byterock commented 4 years ago

You will have to build it yourself.

The instructions are here

https://github.com/pplu/aws-sdk-perl#development-setup

Start by doing a 'git clone' of my working fork/branch

git clone https://github.com/byterock/aws-sdk-perl.git

once you get the first install and build done

checkout my 's3ObjectTagging' branch by going into the 'aws-sdk-perl' dir and enter

git checkout s3ObjectTagging

once that is done you have to get my version of boto. In the 'aws-sdk-perl' dir clone my boto

git clone https://github.com/byterock/botocore.git

then go into the botocore dir and get my branch

git checkout s3-changes

go back up to the 'aws-sdk-perl' dir and then give this command

carton exec builder-bin/gen_classes.pl --classes botocore/botocore/data/cloudfront/2019-03-26/service-2.json

which will rebuild 'cloudfront' for you

This little script should work after you get all of that done

`

!/usr/bin/env perl

use strict; use warnings; use Data::Dumper; use Paws;

my $service = Paws->service( 'CloudFront', region => 'us-east-1', );

my $list = $s3->ListDistributions( MaxItems=>'10' ); warn( "ListDistributions =" . Dumper($list) ); ` I started by getting a distrabution working first via the AWS website and then do a 'Get' to get a config that is working and modify it for the create.

this blog post of mine might help once you get PAWS all compiled