Relanding change to add config to enable S3 file system support.

Pass --config=s3 argument to Bazel to build with S3 file system support.
Change was originally rolled back due to a failure it caused in
//tensorflow/core/kernels:control_flow_ops_test on Macs which is now fixed.

PiperOrigin-RevId: 171579378
diff --git a/configure.py b/configure.py
index 9ca614f..9da49b6 100644
--- a/configure.py
+++ b/configure.py
@@ -991,6 +991,8 @@
                 'with_gcp_support', False, 'gcp')
   set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
                 'with_hdfs_support', False, 'hdfs')
+  set_build_var(environ_cp, 'TF_NEED_S3', 'Amazon S3 File System',
+                'with_s3_support', True, 's3')
   set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
                 False, 'xla')
   set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
diff --git a/tensorflow/BUILD b/tensorflow/BUILD
index 56d0939..1620bb5 100644
--- a/tensorflow/BUILD
+++ b/tensorflow/BUILD
@@ -186,6 +186,12 @@
 )
 
 config_setting(
+    name = "with_s3_support",
+    values = {"define": "with_s3_support=true"},
+    visibility = ["//visibility:public"],
+)
+
+config_setting(
     name = "with_xla_support",
     values = {"define": "with_xla_support=true"},
     visibility = ["//visibility:public"],
diff --git a/tensorflow/core/platform/default/build_config.bzl b/tensorflow/core/platform/default/build_config.bzl
index 51d3729..2c14ea9 100644
--- a/tensorflow/core/platform/default/build_config.bzl
+++ b/tensorflow/core/platform/default/build_config.bzl
@@ -465,6 +465,11 @@
           "//tensorflow/core/platform/hadoop:hadoop_file_system",
       ],
       "//conditions:default": [],
+  }) + select({
+      "//tensorflow:with_s3_support": [
+          "//tensorflow/contrib/s3:s3_file_system",
+      ],
+      "//conditions:default": [],
   })
 
 # TODO(jart, jhseu): Delete when GCP is default on.