cancel
Showing results for 
Search instead for 
Did you mean: 
Eric_Chen
F5 Employee
F5 Employee

Problem this snippet solves:

Create a secure proxy to AWS S3 via iRule/IRuleLX

Related Article: Creating a Secure AWS S3 Proxy with F5 iRulesLX

How to use this snippet:

  1. Install iRule via iRulesLX Workspace
  2. Create iRulesLX plugin
  3. Create AWS role or IAM credentials
  4. Create FQDN pool to AWS S3
  5. Create Virtual Server
  6. Enable OneConnect and WebAcceleration profiles
  7. Assign iRule to Virtual Server

Code :

when HTTP_REQUEST {

    set orig_path [string trimleft [HTTP::path] "/"]
    set key "s3:$orig_path"
    set data [table lookup -notouch $key]

    if { $data eq "" } {
    set RPC_HANDLE [ILX::init aws_s3_rpc_plugin aws_s3_rpc_ext]
    set rpc_response [ILX::call $RPC_HANDLE aws_s3_rpc_add_creds $orig_path]

    set qs [ lindex $rpc_response 0]
    set expires [lindex $rpc_response 1]
    set time_to_expires [lindex $rpc_response 2]
    # save value in cache
    table set $key $qs $time_to_expires $time_to_expires
    } else {
    # use cached value
        set qs $data
    }

}
when HTTP_REQUEST_SEND {
    clientside {

        HTTP::header replace Host "secure-bucket.s3.amazonaws.com"
        # specify bucket
        HTTP::uri "/$orig_path?$qs"
        #log local0. "https://secure-bucket.s3.amazonaws.com[HTTP::uri]"
    }
}
when HTTP_RESPONSE {
    # remove identifying data
    HTTP::header remove "Server"
    HTTP::header remove "x-amz-id-2"
    HTTP::header remove "x-amz-request-id"
    if { [HTTP::status] contains "403"} {
        HTTP::respond 404 content "not found"
    } 
}

Tested this on version:

13.0
Version history
Last update:
‎21-Jul-2017 14:12
Updated by:
Contributors