Search code examples
amazon-s3freeswitchadhearsion

store the recordings on s3 with mod_rayo and mod_http_cache on freeswitch


i'm trying to get my recordings stored on s3.

Here is my rayo.conf.xml:

<configuration name="rayo.conf">
  <settings>
    <param name="max-idle-sec" value="300"/>
  </settings>
  <domain name="localhost" shared-secret="itsasecret">
    <listen type="c2s" port="5222" address="0.0.0.0" acl=""/>
    <users><user name="adhearsion" password="foo"/></users>
  </domain>

  <record>
    <param name="record-file-prefix" value="{profile=s3}http://bucket.domain.com.s3.amazonaws.com/records/"/>
  </record>

</configuration>

Here is my http_cache.conf.xml

<configuration name="http_cache.conf" description="HTTP GET cache">
  <settings>
    <!-- set to true if you want to enable http:// and https:// formats.  Do not use if mod_httapi is also loaded -->
    <param name="enable-file-formats" value="true"/>
    <param name="max-urls" value="10000"/>
    <param name="location" value="$${base_dir}/http_cache"/>
    <param name="default-max-age" value="86400"/>
    <param name="prefetch-thread-count" value="8"/>
    <param name="prefetch-queue-size" value="100"/>
    <!-- absolute path to CA bundle file -->
    <param name="ssl-cacert" value="$${base_dir}/conf/cacert.pem"/>
    <!-- verify certificates -->
    <param name="ssl-verifypeer" value="true"/>
    <!-- verify host name matches certificate -->
    <param name="ssl-verifyhost" value="true"/>
  </settings>
<profiles>
    <profile name='s3'>
        <aws-s3>
            <access-key-id>
                <![CDATA[AWS_KEY_ID]]>
            </access-key-id>
            <secret-access-key>
                <![CDATA[AWS_KEY_SECRET]]>
            </secret-access-key>
        </aws-s3>
        <domains>
          <domain name='bucket.domain.com.s3.amazonaws.com' />
        </domains>
    </profile>
</profiles>
</configuration>

Here is the debug log:

2014-08-10 01:03:19.405172 [ERR] mod_http_cache.c:351 Received HTTP error 403 trying to save /usr/http_cache/64/6ee5dd-bb6d-49a4-96cc-34bd54ab9827.wav to http://bucket.domain.com.s3.amazonaws.com/records/b5ffe577-c8c1-48c5-847e-a330ddc7b6b9-2.wav

2014-08-10 01:03:19.405172 [ERR] mod_http_cache.c:351 Received HTTP error 403 trying to save /usr/http_cache/64/6ee5dd-bb6d-49a4-96cc-34bd54ab9827.wav to http://bucket.domain.com.s3.amazonaws.com/records/b5ffe577-c8c1-48c5-847e-a330ddc7b6b9-2.wav
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Content-Type] = [log/data]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Content-Length] = [116]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Log-Level] = [5]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Text-Channel] = [3]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Log-File] = [switch_core_session.c]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Log-Func] = [switch_core_session_thread]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [Log-Line] = [1632]
[DEBUG] esl.c:1316 esl_recv_event() RECV HEADER [User-Data] = [b5ffe577-c8c1-48c5-847e-a330ddc7b6b9]
[DEBUG] esl.c:1480 esl_recv_event() RECV MESSAGE
Event-Name: SOCKET_DATA
Content-Type: log/data
Content-Length: 116
Log-Level: 5
Text-Channel: 3
Log-File: switch_core_session.c
Log-Func: switch_core_session_thread
Log-Line: 1632
User-Data: b5ffe577-c8c1-48c5-847e-a330ddc7b6b9
Content-Length: 116

2014-08-10 01:03:19.425141 [NOTICE] switch_core_session.c:1632 Session 2 (sofia/internal/[email protected]) Ended

I tried to point it to a local server and turns out the only params i get are is the name of the file: audio_file.wav. looks like it's not sending the file properly...

I double checked my credentials so i'm pretty sure that's not the issue. Also, the records directory is writable by world for now.


Solution

  • Two issues were found with this configuration:

    1. The virtual host URL was not parsed properly by FreeSWITCH.
    2. The whitespace around the S3 key configuration was not stripped.

    Master branch of FreeSWITCH has the fixes: see commits b60df39b96 and 3b45ef90a.

    Also- make sure you do not have mod_httapi loaded.