My Swift Lambda for AWS works fine, until I add URLSession

I've got a Swift Lambda made for AWS. I can run it in Xcode locally or deploy to AWS using Docker and the Docker build script.

If I add URLSession() to my code, I can still run it locally via Xcode, but the Docker build breaks:

[35/36] Compiling HelloWorld main.swift

/usr/bin/ld.gold: error: cannot find -lcurl
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionEasyCodeDescription: error: undefined reference to 'curl_easy_strerror'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionEasyHandleInit: error: undefined reference to 'curl_easy_init'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionEasyHandleDeinit: error: undefined reference to 'curl_easy_cleanup'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionEasyHandleSetPauseState: error: undefined reference to 'curl_easy_pause'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleInit: error: undefined reference to 'curl_multi_init'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleDeinit: error: undefined reference to 'curl_multi_cleanup'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleAddHandle: error: undefined reference to 'curl_multi_add_handle'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleRemoveHandle: error: undefined reference to 'curl_multi_remove_handle'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleAssign: error: undefined reference to 'curl_multi_assign'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleAction: error: undefined reference to 'curl_multi_socket_action'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionMultiHandleInfoRead: error: undefined reference to 'curl_multi_info_read'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_setopt_ptr: error: undefined reference to 'curl_easy_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_setopt_int: error: undefined reference to 'curl_easy_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_setopt_long: error: undefined reference to 'curl_easy_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_setopt_int64: error: undefined reference to 'curl_easy_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_getinfo_long: error: undefined reference to 'curl_easy_getinfo'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_getinfo_double: error: undefined reference to 'curl_easy_getinfo'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_easy_getinfo_charp: error: undefined reference to 'curl_easy_getinfo'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_multi_setopt_ptr: error: undefined reference to 'curl_multi_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_multi_setopt_l: error: undefined reference to 'curl_multi_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_multi_setopt_sf: error: undefined reference to 'curl_multi_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSession_multi_setopt_tf: error: undefined reference to 'curl_multi_setopt'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionInit: error: undefined reference to 'curl_global_init'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionCurlVersionString: error: undefined reference to 'curl_version'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionCurlVersionInfo: error: undefined reference to 'curl_version_info'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionSListAppend: error: undefined reference to 'curl_slist_append'
/usr/lib/swift_static/linux/libCFURLSessionInterface.a(CFURLSessionInterface.c.o):CFURLSessionInterface.c:function CFURLSessionSListFreeAll: error: undefined reference to 'curl_slist_free_all'

clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

[35/36] Linking HelloWorld

I am using this build script:

docker run \
    --rm \
    --volume "$(pwd)/:/src" \
    --workdir "/src/" \
    swift:5.3.1-amazonlinux2 \
    swift build --product HelloWorld -c release -Xswiftc -static-stdlib

I've also tried 5.4.3 and 5.5.0 -amazonlinux2, but they each give a different set of errors.

How do I get around this?

Here's how to fix this:

docker run \
  --rm \
  --volume "$(pwd)/:/src" \
  --workdir "/src/" \
  swift:5.3.1-amazonlinux2 \
  /bin/bash -c "yum install -y libcurl-devel && \
  swift build --product HelloWorld -c release -Xswiftc -static-stdlib"

This will install what is needed for the linking to succeed.

My Swift Lambda for AWS works fine, until I add URLSession
 
 
Q