0

I'm attempting to setup a craft site with AWS S3/ Cloudfront. I found this tutorial (from some time ago): https://nystudio107.com/blog/using-aws-s3-buckets-cloudfront-distribution-with-craft-cms

I'm not seeming to get this to work though. Here's a run down of what I did. I had a site that we are migrating to new hosting. All asset files were on an S3/cloudfront combo.

I had copies of all assets, and re-uploaded them to a new amazon account in an s3 bucket. The tutorial link took me through the process:

I made an s3 bucket named mysitecontent (this isn't the real bucket name) I made it to block all public access and added this bucket policy:

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "AllowCloudFrontServicePrincipal",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudfront.amazonaws.com"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mysitecontent/*",
            "Condition": {
                "StringEquals": {
                    "AWS:SourceArn": "arn:aws:cloudfront::196144777777:distribution/E25EJ0AJ777777"
                }
            }
        }
    ]
}

(numbers changed to protect the innocent!) I didn't make any other changes.

Then I created a cloudfront Distribution (E25EJ0AJ777777 -number changed again!)

I set it's origin to the s3-mysitecontent-bucket with a domain of mysitecontent.s3.us-west-1.amazonaws.com. Origin access was set to 'origin access control settings". (i'm not sure if that should have been legacy access identities.)

Then in IAM, I created a policy mysite-content-bucket-access using this Json

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "acm:ListCertificates",
                "cloudfront:GetDistribution",
                "cloudfront:GetStreamingDistribution",
                "cloudfront:GetDistributionConfig",
                "cloudfront:ListDistributions",
                "cloudfront:ListCloudFrontOriginAccessIdentities",
                "cloudfront:CreateInvalidation",
                "cloudfront:GetInvalidation",
                "cloudfront:ListInvalidations",
                "elasticloadbalancing:DescribeLoadBalancers",
                "iam:ListServerCertificates",
                "sns:ListSubscriptionsByTopic",
                "sns:ListTopics",
                "waf:GetWebACL",
                "waf:ListWebACLs"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListAllMyBuckets"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::mysitecontent"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::mysitecontent/*"
            ]
        }
    ]
}

Then I created a group called s3-mysitecontent-group. and added my mysitecontent-bucket-access to that group.

Lastly I added a new user mssitecontent-user to the group.

Since this site was being migrated I went into my volumes in the Craft dashboard and changed the S3 settings for each folder in my S3 bucket (each folder is set to a separate asset) to my new user credentials and AWS details.

Here is the problem. In the Craft dashboard, I go to media and can upload, and it works and when I go into details of the media, if I click download the asset (in this case an image) downloads, but no thumbnails show up for the image and in the frontend I get broken images.

If I look in my AWS S3 dashboard the newly uploaded images don't show up in any of the bucket directories or in the bucket at all.

Is there any way to actually test this connection and make sure it's working properly or did I blatantly miss something in my setup?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.