laurilehmijoki / configure-s3-website

Ruby gem for configuring an AWS S3 bucket to function as a website
MIT License
40 stars 20 forks source link

Including 2 (both) AWS conditions in a redirect. #20

Closed dirkcuys closed 5 years ago

dirkcuys commented 7 years ago

I'm trying setup a redirect that only redirects a given prefix if it doesn't exist on the site:

  - condition:
      key_prefix_equals: en/courses/
      http_error_code_returned_equals: 404
    redirect:
      host_name: courses.p2pu.org
      protocol: https
      http_redirect_code: 301

But this doesn't work when I run s3_website push.

dirkcuys commented 7 years ago

I think I found the error. It's not actually s3_website push that errors, but s3_website cfg apply and the error is:

expected params[:website_configuration][:routing_rules][0][:condition][:http_error_code_returned_equals] to be a String, got value 404 (class: Fixnum) instead. (ArgumentError)

I suspect that the problem is related to how http_redirect_code is managed here

I worked around the problem by changing my config to:

  - condition:
      key_prefix_equals: en/courses/
      http_error_code_returned_equals: "404"
    redirect:
      host_name: courses.p2pu.org
      protocol: https
      http_redirect_code: 301