AWS S3 Proxy: TCL iRule

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 :


    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

    clientside {

        HTTP::header replace Host ""
        # specify bucket
        HTTP::uri "/$orig_path?$qs"
        #log local0. "[HTTP::uri]"
    # 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:

Published Jul 21, 2017
Version 1.0

Was this article helpful?

No CommentsBe the first to comment