From d2c028c09cebc47da69c77f3d92b3f6505ba63b4 Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sat, 19 Nov 2022 02:53:40 +0300 Subject: [PATCH 01/13] rust hello world --- .gitignore | 1 + rust-1.65/.gitignore | 1 + rust-1.65/Cargo.lock | 695 ++++++++++++++++++++++++++++++++++++++++++ rust-1.65/Cargo.toml | 12 + rust-1.65/Makefile | 2 + rust-1.65/README.md | 4 + rust-1.65/src/main.rs | 19 ++ 7 files changed, 734 insertions(+) create mode 100644 rust-1.65/.gitignore create mode 100644 rust-1.65/Cargo.lock create mode 100644 rust-1.65/Cargo.toml create mode 100644 rust-1.65/Makefile create mode 100644 rust-1.65/README.md create mode 100644 rust-1.65/src/main.rs diff --git a/.gitignore b/.gitignore index 6688b15..6eb6443 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .terraform functions/*/src/vendor */node_modules +.idea diff --git a/rust-1.65/.gitignore b/rust-1.65/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/rust-1.65/.gitignore @@ -0,0 +1 @@ +/target diff --git a/rust-1.65/Cargo.lock b/rust-1.65/Cargo.lock new file mode 100644 index 0000000..b97ea84 --- /dev/null +++ b/rust-1.65/Cargo.lock @@ -0,0 +1,695 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async-stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" + +[[package]] +name = "futures-executor" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + +[[package]] +name = "futures-macro" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + +[[package]] +name = "futures-task" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" + +[[package]] +name = "futures-util" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "lambda-battle" +version = "0.1.0" +dependencies = [ + "lambda_runtime", + "log", + "serde_json", + "tokio", +] + +[[package]] +name = "lambda_runtime" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7d15b949b5ecc044bfe512a959df09b055a599229357519e4a01d06d94399f" +dependencies = [ + "async-stream", + "bytes", + "futures", + "http", + "hyper", + "lambda_runtime_api_client", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower", + "tracing", +] + +[[package]] +name = "lambda_runtime_api_client" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7210012be904051520f0dc502140ba599bae3042b65b3737b87727f1aa88a7d6" +dependencies = [ + "http", + "hyper", + "tokio", + "tower-service", +] + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "num_cpus" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/rust-1.65/Cargo.toml b/rust-1.65/Cargo.toml new file mode 100644 index 0000000..8f51733 --- /dev/null +++ b/rust-1.65/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "lambda-battle" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1", features = ["full"] } +serde_json = "1" +log = "0.4" +lambda_runtime = "0.7.1" diff --git a/rust-1.65/Makefile b/rust-1.65/Makefile new file mode 100644 index 0000000..cb48bb7 --- /dev/null +++ b/rust-1.65/Makefile @@ -0,0 +1,2 @@ +release: + cargo build --target=x86_64-unknown-linux-musl --release diff --git a/rust-1.65/README.md b/rust-1.65/README.md new file mode 100644 index 0000000..c78addf --- /dev/null +++ b/rust-1.65/README.md @@ -0,0 +1,4 @@ +Runtime: Custom runtime on Amazon Linux 2 +handler: main + +file should be called as `bootstrap` diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs new file mode 100644 index 0000000..ce11211 --- /dev/null +++ b/rust-1.65/src/main.rs @@ -0,0 +1,19 @@ +use lambda_runtime::{service_fn, LambdaEvent, Error}; +use serde_json::{json, Value}; + +#[tokio::main] +async fn main() -> Result<(), Error> { + let func = service_fn(func); + lambda_runtime::run(func).await?; + Ok(()) +} + +async fn func(event: LambdaEvent) -> Result { + let (event, _context) = event.into_parts(); + let first_name = event["firstName"].as_str(); + + match first_name { + None => Ok(json!({"message": "no name"})), + Some(name) => Ok(json!({ "message": format!("Hello, {}!", name) })) + } +} From e711782d1f1c02949869f60715c09e7751cc351e Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 27 Nov 2022 01:40:32 +0100 Subject: [PATCH 02/13] function deploy --- main.tf | 7 ++++ rust-1.65/Dockerfile | 9 +++++ rust-1.65/Makefile | 20 +++++++++- rust-1.65/README.md | 1 + rust-1.65/main.tf | 94 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 rust-1.65/Dockerfile create mode 100644 rust-1.65/main.tf diff --git a/main.tf b/main.tf index d18e6b2..ec49615 100644 --- a/main.tf +++ b/main.tf @@ -59,6 +59,12 @@ module "ruby-2_7-lambda" { depends_on = [aws_dynamodb_table.data] } +module "rust-1_65-lambda" { + source = "./rust-1.65" + data_table = aws_dynamodb_table.data + depends_on = [aws_dynamodb_table.data] +} + resource "aws_apigatewayv2_api" "gateway" { name = "lambda-battle-api" protocol_type = "HTTP" @@ -67,6 +73,7 @@ resource "aws_apigatewayv2_api" "gateway" { locals { lambda_resources = { "ruby-2_7-x86" = { "module" = module.ruby-2_7-lambda } + "rust-1_65-x86" = { "module" = module.rust-1_65-lambda } } } diff --git a/rust-1.65/Dockerfile b/rust-1.65/Dockerfile new file mode 100644 index 0000000..a24de1f --- /dev/null +++ b/rust-1.65/Dockerfile @@ -0,0 +1,9 @@ +FROM rust:1.65.0-alpine + +RUN rustup target add x86_64-unknown-linux-musl + +RUN apk add --update \ + musl-dev \ + && rm -rf /var/cache/apk/* + +WORKDIR /src diff --git a/rust-1.65/Makefile b/rust-1.65/Makefile index cb48bb7..25e3486 100644 --- a/rust-1.65/Makefile +++ b/rust-1.65/Makefile @@ -1,2 +1,18 @@ -release: - cargo build --target=x86_64-unknown-linux-musl --release +release: build-image + docker run \ + -v ${PWD}:/src \ + -v cargo-bin:/usr/local/cargo/bin \ + -v cargo-registry-index:/usr/local/cargo/registry/index \ + -v cargo-registry-cache:/usr/local/cargo/registry/cache \ + -v cargo-git:/usr/local/cargo/registry/git/db \ + rust-builder:1.65 cargo build --release --target=x86_64-unknown-linux-musl --verbose --frozen + +build-image: + docker build -t rust-builder:1.65 . + +run: build-image + docker run -it rust-builder:1.65 /bin/sh + +prepare: release + cp target/x86_64-unknown-linux-musl/release/lambda-battle dist/src/bootstrap + diff --git a/rust-1.65/README.md b/rust-1.65/README.md index c78addf..aa58bdd 100644 --- a/rust-1.65/README.md +++ b/rust-1.65/README.md @@ -1,4 +1,5 @@ Runtime: Custom runtime on Amazon Linux 2 + handler: main file should be called as `bootstrap` diff --git a/rust-1.65/main.tf b/rust-1.65/main.tf new file mode 100644 index 0000000..2079105 --- /dev/null +++ b/rust-1.65/main.tf @@ -0,0 +1,94 @@ +variable "data_table" {} + +resource "aws_iam_role" "iam_for_lambda" { + name = "rust-1.65_lambda_role" + assume_role_policy = jsonencode({ + "Version" : "2012-10-17", + "Statement" : [ + { + "Action" : "sts:AssumeRole", + "Principal" : { + "Service" : "lambda.amazonaws.com" + }, + "Effect" : "Allow", + "Sid" : "" + } + ] + }) +} + +resource "aws_iam_policy" "lambda_policy" { + name = "ruby-2.7_battle_lambda_role" + path = "/" + description = "AWS IAM Policy for ruby 2.7 lambda" + + policy = jsonencode({ + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": "arn:aws:logs:*:*:*", + "Effect": "Allow" + }, + { + "Action": [ + "dynamodb:BatchGetItem", + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", + "dynamodb:BatchWriteItem", + "dynamodb:PutItem", + "dynamodb:UpdateItem" + ], + "Resource": var.data_table.arn, + "Effect": "Allow" + } + ] + }) +} + +resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" { + role = aws_iam_role.iam_for_lambda.name + policy_arn = aws_iam_policy.lambda_policy.arn +} + + +resource "null_resource" "build_app" { + provisioner "local-exec" { + command = "cd ${path.module} && make prepare" + } +} + +locals { + dist_path = "${path.module}/dist/lambda.zip" +} + +data "archive_file" "source" { + type = "zip" + source_dir = "${path.module}/dist/src" + output_path = local.dist_path + depends_on = [null_resource.build_app] +} + +resource "aws_lambda_function" "test_lambda" { + function_name = "rust-1.65_lambda" + role = aws_iam_role.iam_for_lambda.arn + handler = "main" + runtime = "provided.al2" + source_code_hash = data.archive_file.source.output_base64sha256 + + depends_on = [ + data.archive_file.source, + aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role, + ] + + environment { + variables = { + "TABLE" = var.data_table.name + } + } +} From 84f2a411f5d32ab438e8f38cb6f027ff5d1517bd Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 27 Nov 2022 15:54:16 +0300 Subject: [PATCH 03/13] try to deploy --- .terraform.lock.hcl | 21 ++ main.tf | 10 - rust-1.65/.gitignore | 1 + rust-1.65/Cargo.lock | 822 +++++++++++++++++++++++++++++++++++++++++- rust-1.65/Cargo.toml | 3 + rust-1.65/Makefile | 3 +- rust-1.65/main.tf | 18 +- rust-1.65/src/main.rs | 9 +- terraform.tfstate | 9 + 9 files changed, 864 insertions(+), 32 deletions(-) create mode 100644 terraform.tfstate diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 31d0c35..d522111 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -5,6 +5,7 @@ provider "registry.terraform.io/hashicorp/archive" { version = "2.2.0" hashes = [ "h1:62mVchC1L6vOo5QS9uUf52uu0emsMM+LsPQJ1BEaTms=", + "h1:CIWi5G6ob7p2wWoThRQbOB8AbmFlCzp7Ka81hR3cVp0=", "zh:06bd875932288f235c16e2237142b493c2c2b6aba0e82e8c85068332a8d2a29e", "zh:0c681b481372afcaefddacc7ccdf1d3bb3a0c0d4678a526bc8b02d0c331479bc", "zh:100fc5b3fc01ea463533d7bbfb01cb7113947a969a4ec12e27f5b2be49884d6c", @@ -23,6 +24,7 @@ provider "registry.terraform.io/hashicorp/aws" { version = "4.25.0" constraints = ">= 4.17.1" hashes = [ + "h1:0dYkCnmIGkx+TlvUy21GpK7/8cCfN/fiZjHV+AAt3Xw=", "h1:JyQAQ3YrE4utVAQsLGy1LjMbAzzRI/X2XsrY7CFBGxw=", "zh:51fddc33f289108f60c2de78537f758ae913b2614187abfc3f560f9dd277bc1a", "zh:5a2bfa0725a8941f12e775eb9c44582ec237a664321a740d8283e9b56452f2ad", @@ -38,3 +40,22 @@ provider "registry.terraform.io/hashicorp/aws" { "zh:fb0a75edb943847354c759a665edb93fd7945b892be7d0511c6708785abf090c", ] } + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.1" + hashes = [ + "h1:FbGfc+muBsC17Ohy5g806iuI1hQc4SIexpYCrQHQd8w=", + "zh:58ed64389620cc7b82f01332e27723856422820cfd302e304b5f6c3436fb9840", + "zh:62a5cc82c3b2ddef7ef3a6f2fedb7b9b3deff4ab7b414938b08e51d6e8be87cb", + "zh:63cff4de03af983175a7e37e52d4bd89d990be256b16b5c7f919aff5ad485aa5", + "zh:74cb22c6700e48486b7cabefa10b33b801dfcab56f1a6ac9b6624531f3d36ea3", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:79e553aff77f1cfa9012a2218b8238dd672ea5e1b2924775ac9ac24d2a75c238", + "zh:a1e06ddda0b5ac48f7e7c7d59e1ab5a4073bbcf876c73c0299e4610ed53859dc", + "zh:c37a97090f1a82222925d45d84483b2aa702ef7ab66532af6cbcfb567818b970", + "zh:e4453fbebf90c53ca3323a92e7ca0f9961427d2f0ce0d2b65523cc04d5d999c2", + "zh:e80a746921946d8b6761e77305b752ad188da60688cfd2059322875d363be5f5", + "zh:fbdb892d9822ed0e4cb60f2fedbdbb556e4da0d88d3b942ae963ed6ff091e48f", + "zh:fca01a623d90d0cad0843102f9b8b9fe0d3ff8244593bd817f126582b52dd694", + ] +} diff --git a/main.tf b/main.tf index ec49615..58a87b7 100644 --- a/main.tf +++ b/main.tf @@ -5,20 +5,10 @@ terraform { version = ">= 4.17.1" } } - - backend "s3" { - bucket = "fwd-remote-state" - key = "lambda-battle.tfstate" - region = "eu-central-1" - encrypt = true - dynamodb_table = "tf-remote-state-locks" - profile = "fwd-retro" - } } provider "aws" { region = "eu-central-1" - profile = "fwd-retro" default_tags { tags = { diff --git a/rust-1.65/.gitignore b/rust-1.65/.gitignore index ea8c4bf..4f96631 100644 --- a/rust-1.65/.gitignore +++ b/rust-1.65/.gitignore @@ -1 +1,2 @@ /target +/dist diff --git a/rust-1.65/Cargo.lock b/rust-1.65/Cargo.lock index b97ea84..7062674 100644 --- a/rust-1.65/Cargo.lock +++ b/rust-1.65/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + [[package]] name = "async-stream" version = "0.3.3" @@ -29,17 +38,331 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "aws-config" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56a636c44c77fa18bdba56126a34d30cfe5538fe88f7d34988fa731fee143ddd" +dependencies = [ + "aws-http", + "aws-sdk-sso", + "aws-sdk-sts", + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-json", + "aws-smithy-types", + "aws-types", + "bytes", + "hex", + "http", + "hyper", + "ring", + "time", + "tokio", + "tower", + "tracing", + "zeroize", +] + +[[package]] +name = "aws-endpoint" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ca8f374874f6459aaa88dc861d7f5d834ca1ff97668eae190e97266b5f6c3fb" +dependencies = [ + "aws-smithy-http", + "aws-smithy-types", + "aws-types", + "http", + "regex", + "tracing", +] + +[[package]] +name = "aws-http" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78d41e19e779b73463f5f0c21b3aacc995f4ba783ab13a7ae9f5dfb159a551b4" +dependencies = [ + "aws-smithy-http", + "aws-smithy-types", + "aws-types", + "bytes", + "http", + "http-body", + "lazy_static", + "percent-encoding", + "pin-project-lite", + "tracing", +] + +[[package]] +name = "aws-sdk-dynamodb" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28e71b3f397f2f39cb15fbba1c9105a88fd12b665e51100f02837667f27294f9" +dependencies = [ + "aws-endpoint", + "aws-http", + "aws-sig-auth", + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-json", + "aws-smithy-types", + "aws-types", + "bytes", + "fastrand", + "http", + "tokio-stream", + "tower", +] + +[[package]] +name = "aws-sdk-sso" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86dcb1cb71aa8763b327542ead410424515cff0cde5b753eedd2917e09c63734" +dependencies = [ + "aws-endpoint", + "aws-http", + "aws-sig-auth", + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-json", + "aws-smithy-types", + "aws-types", + "bytes", + "http", + "tokio-stream", + "tower", +] + +[[package]] +name = "aws-sdk-sts" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdfcf584297c666f6b472d5368a78de3bc714b6e0a53d7fbf76c3e347c292ab1" +dependencies = [ + "aws-endpoint", + "aws-http", + "aws-sig-auth", + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-query", + "aws-smithy-types", + "aws-smithy-xml", + "aws-types", + "bytes", + "http", + "tower", +] + +[[package]] +name = "aws-sig-auth" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cbe7b2be9e185c1fbce27fc9c41c66b195b32d89aa099f98768d9544221308" +dependencies = [ + "aws-sigv4", + "aws-smithy-http", + "aws-types", + "http", + "tracing", +] + +[[package]] +name = "aws-sigv4" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ff4cff8c4a101962d593ba94e72cd83891aecd423f0c6e3146bff6fb92c9e3" +dependencies = [ + "aws-smithy-http", + "form_urlencoded", + "hex", + "http", + "once_cell", + "percent-encoding", + "regex", + "ring", + "time", + "tracing", +] + +[[package]] +name = "aws-smithy-async" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b3442b4c5d3fc39891a2e5e625735fba6b24694887d49c6518460fde98247a9" +dependencies = [ + "futures-util", + "pin-project-lite", + "tokio", + "tokio-stream", +] + +[[package]] +name = "aws-smithy-client" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff28d553714f8f54cd921227934fc13a536a1c03f106e56b362fd57e16d450ad" +dependencies = [ + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-types", + "bytes", + "fastrand", + "http", + "http-body", + "hyper", + "hyper-rustls", + "lazy_static", + "pin-project-lite", + "tokio", + "tower", + "tracing", +] + +[[package]] +name = "aws-smithy-http" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf58ed4fefa61dbf038e5421a521cbc2c448ef69deff0ab1d915d8a10eda5664" +dependencies = [ + "aws-smithy-types", + "bytes", + "bytes-utils", + "futures-core", + "http", + "http-body", + "hyper", + "once_cell", + "percent-encoding", + "pin-project-lite", + "pin-utils", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "aws-smithy-http-tower" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20c96d7bd35e7cf96aca1134b2f81b1b59ffe493f7c6539c051791cbbf7a42d3" +dependencies = [ + "aws-smithy-http", + "bytes", + "http", + "http-body", + "pin-project-lite", + "tower", + "tracing", +] + +[[package]] +name = "aws-smithy-json" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8324ba98c8a94187723cc16c37aefa09504646ee65c3d2c3af495bab5ea701b" +dependencies = [ + "aws-smithy-types", +] + +[[package]] +name = "aws-smithy-query" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83834ed2ff69ea6f6657baf205267dc2c0abe940703503a3e5d60ce23be3d306" +dependencies = [ + "aws-smithy-types", + "urlencoding", +] + +[[package]] +name = "aws-smithy-types" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b02e06ea63498c43bc0217ea4d16605d4e58d85c12fc23f6572ff6d0a840c61" +dependencies = [ + "itoa", + "num-integer", + "ryu", + "time", +] + +[[package]] +name = "aws-smithy-xml" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246e9f83dd1fdf5d347fa30ae4ad30a9d1d42ce4cd74a93d94afa874646f94cd" +dependencies = [ + "xmlparser", +] + +[[package]] +name = "aws-types" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05701d32da168b44f7ee63147781aed8723e792cc131cb9b18363b5393f17f70" +dependencies = [ + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-types", + "http", + "rustc_version", + "tracing", + "zeroize", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + [[package]] name = "bytes" -version = "1.2.1" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" + +[[package]] +name = "bytes-utils" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +checksum = "e47d3a8076e283f3acd27400535992edb3ba4b5bb72f8891ad8fbe7932a7d4b9" +dependencies = [ + "bytes", + "either", +] + +[[package]] +name = "cc" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" @@ -47,12 +370,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.25" @@ -142,6 +505,31 @@ dependencies = [ "slab", ] +[[package]] +name = "h2" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -151,6 +539,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "0.2.8" @@ -195,6 +589,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", + "h2", "http", "http-body", "httparse", @@ -208,18 +603,64 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d" +dependencies = [ + "http", + "hyper", + "log", + "rustls", + "rustls-native-certs", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lambda-battle" version = "0.1.0" dependencies = [ + "aws-config", + "aws-sdk-dynamodb", "lambda_runtime", "log", + "serde", "serde_json", "tokio", ] @@ -256,6 +697,12 @@ dependencies = [ "tower-service", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.137" @@ -296,7 +743,26 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.42.0", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", ] [[package]] @@ -315,6 +781,12 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "parking_lot" version = "0.12.1" @@ -335,9 +807,15 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + [[package]] name = "pin-project" version = "1.0.12" @@ -397,18 +875,141 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +dependencies = [ + "base64", +] + [[package]] name = "ryu" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys 0.36.1", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" + [[package]] name = "serde" version = "1.0.147" @@ -431,9 +1032,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.88" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ "itoa", "ryu", @@ -474,6 +1075,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "syn" version = "1.0.103" @@ -485,6 +1092,32 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "time" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +dependencies = [ + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", +] + [[package]] name = "tokio" version = "1.22.0" @@ -516,6 +1149,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + [[package]] name = "tokio-stream" version = "0.1.11" @@ -527,6 +1171,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -537,6 +1195,7 @@ dependencies = [ "futures-util", "pin-project", "pin-project-lite", + "tokio", "tower-layer", "tower-service", "tracing", @@ -599,6 +1258,18 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "urlencoding" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" + [[package]] name = "want" version = "0.3.0" @@ -615,6 +1286,80 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "winapi" version = "0.3.9" @@ -637,6 +1382,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -644,12 +1402,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_x86_64_msvc 0.42.0", ] [[package]] @@ -658,24 +1416,48 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" @@ -688,8 +1470,26 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] +name = "xmlparser" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d25c75bf9ea12c4040a97f829154768bbbce366287e2dc044af160cd79a13fd" + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" diff --git a/rust-1.65/Cargo.toml b/rust-1.65/Cargo.toml index 8f51733..6c455eb 100644 --- a/rust-1.65/Cargo.toml +++ b/rust-1.65/Cargo.toml @@ -8,5 +8,8 @@ edition = "2021" [dependencies] tokio = { version = "1", features = ["full"] } serde_json = "1" +serde = "1" log = "0.4" lambda_runtime = "0.7.1" +aws-sdk-dynamodb = "0.21.0" +aws-config = "0.51.0" diff --git a/rust-1.65/Makefile b/rust-1.65/Makefile index 25e3486..635815d 100644 --- a/rust-1.65/Makefile +++ b/rust-1.65/Makefile @@ -5,7 +5,7 @@ release: build-image -v cargo-registry-index:/usr/local/cargo/registry/index \ -v cargo-registry-cache:/usr/local/cargo/registry/cache \ -v cargo-git:/usr/local/cargo/registry/git/db \ - rust-builder:1.65 cargo build --release --target=x86_64-unknown-linux-musl --verbose --frozen + rust-builder:1.65 cargo build --release --target=x86_64-unknown-linux-musl --verbose build-image: docker build -t rust-builder:1.65 . @@ -14,5 +14,6 @@ run: build-image docker run -it rust-builder:1.65 /bin/sh prepare: release + mkdir -p dist/src cp target/x86_64-unknown-linux-musl/release/lambda-battle dist/src/bootstrap diff --git a/rust-1.65/main.tf b/rust-1.65/main.tf index 2079105..7f04c20 100644 --- a/rust-1.65/main.tf +++ b/rust-1.65/main.tf @@ -18,9 +18,9 @@ resource "aws_iam_role" "iam_for_lambda" { } resource "aws_iam_policy" "lambda_policy" { - name = "ruby-2.7_battle_lambda_role" + name = "rust-1.65_battle_lambda_role" path = "/" - description = "AWS IAM Policy for ruby 2.7 lambda" + description = "AWS IAM Policy for rust 1.65 lambda" policy = jsonencode({ "Version": "2012-10-17", @@ -74,16 +74,19 @@ data "archive_file" "source" { depends_on = [null_resource.build_app] } -resource "aws_lambda_function" "test_lambda" { +resource "aws_lambda_function" "lambda" { function_name = "rust-1.65_lambda" role = aws_iam_role.iam_for_lambda.arn - handler = "main" + handler = "func" runtime = "provided.al2" source_code_hash = data.archive_file.source.output_base64sha256 + filename = local.dist_path + memory_size = 128 + timeout = 3 depends_on = [ - data.archive_file.source, aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role, + data.archive_file.source, ] environment { @@ -92,3 +95,8 @@ resource "aws_lambda_function" "test_lambda" { } } } + +output "lambda" { + value = aws_lambda_function.lambda +} + diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index ce11211..ec1c807 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -10,10 +10,9 @@ async fn main() -> Result<(), Error> { async fn func(event: LambdaEvent) -> Result { let (event, _context) = event.into_parts(); - let first_name = event["firstName"].as_str(); - match first_name { - None => Ok(json!({"message": "no name"})), - Some(name) => Ok(json!({ "message": format!("Hello, {}!", name) })) - } + Ok(json!({ + "statusCode": 200, + "body": "hello world" + })) } diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..7cdafc4 --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,9 @@ +{ + "version": 4, + "terraform_version": "1.3.4", + "serial": 168, + "lineage": "fe764ffe-dcf3-8c88-0609-8785668027fa", + "outputs": {}, + "resources": [], + "check_results": null +} From 7df4abee67007a7005b620ff178ea8b318f39f34 Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Mon, 28 Nov 2022 21:10:08 +0300 Subject: [PATCH 04/13] fixed lambda name --- rust-1.65/main.tf | 5 ++--- terraform.tfstate | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/rust-1.65/main.tf b/rust-1.65/main.tf index 7f04c20..e658fdc 100644 --- a/rust-1.65/main.tf +++ b/rust-1.65/main.tf @@ -75,9 +75,9 @@ data "archive_file" "source" { } resource "aws_lambda_function" "lambda" { - function_name = "rust-1.65_lambda" + function_name = "rust_1_65_lambda" role = aws_iam_role.iam_for_lambda.arn - handler = "func" + handler = "main" runtime = "provided.al2" source_code_hash = data.archive_file.source.output_base64sha256 filename = local.dist_path @@ -86,7 +86,6 @@ resource "aws_lambda_function" "lambda" { depends_on = [ aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role, - data.archive_file.source, ] environment { diff --git a/terraform.tfstate b/terraform.tfstate index 7cdafc4..06aff4b 100644 --- a/terraform.tfstate +++ b/terraform.tfstate @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.3.4", - "serial": 168, + "serial": 305, "lineage": "fe764ffe-dcf3-8c88-0609-8785668027fa", "outputs": {}, "resources": [], From cc1ee63aa29705c31a1c80f6649eb89f642fe33b Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Mon, 28 Nov 2022 22:29:17 +0300 Subject: [PATCH 05/13] validate request --- rust-1.65/Cargo.lock | 155 +++++++++++++++++++++++++++++++++++++++++- rust-1.65/Cargo.toml | 2 +- rust-1.65/src/main.rs | 47 ++++++++++--- 3 files changed, 191 insertions(+), 13 deletions(-) diff --git a/rust-1.65/Cargo.lock b/rust-1.65/Cargo.lock index 7062674..a124d8f 100644 --- a/rust-1.65/Cargo.lock +++ b/rust-1.65/Cargo.lock @@ -324,6 +324,24 @@ dependencies = [ "zeroize", ] +[[package]] +name = "aws_lambda_events" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20e4623e6898c4590b27eb26d64f498513b9e4c7b52537f64f75d3f423483c51" +dependencies = [ + "base64", + "bytes", + "chrono", + "http", + "http-body", + "http-serde", + "query_map", + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "base64" version = "0.13.1" @@ -347,6 +365,9 @@ name = "bytes" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +dependencies = [ + "serde", +] [[package]] name = "bytes-utils" @@ -370,6 +391,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + [[package]] name = "core-foundation" version = "0.9.3" @@ -392,6 +424,15 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + [[package]] name = "fastrand" version = "1.8.0" @@ -567,6 +608,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-serde" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e272971f774ba29341db2f686255ff8a979365a26fb9e4277f6b6d9ec0cdd5e" +dependencies = [ + "http", + "serde", +] + [[package]] name = "httparse" version = "1.8.0" @@ -618,6 +669,16 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -658,13 +719,35 @@ version = "0.1.0" dependencies = [ "aws-config", "aws-sdk-dynamodb", - "lambda_runtime", + "lambda_http", "log", "serde", "serde_json", "tokio", ] +[[package]] +name = "lambda_http" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e99edb20005e6456db8f1bb5abec3cf7787640b456dda195c1a3216ec4397ce8" +dependencies = [ + "aws_lambda_events", + "base64", + "bytes", + "encoding_rs", + "http", + "http-body", + "hyper", + "lambda_runtime", + "mime", + "percent-encoding", + "serde", + "serde_json", + "serde_urlencoded", + "url", +] + [[package]] name = "lambda_runtime" version = "0.7.1" @@ -734,6 +817,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "mio" version = "0.8.5" @@ -857,6 +946,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "query_map" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4465aacac3bebc9484cf7a56dc8b2d7feacb657da6002a9198b4f7af4247a204" +dependencies = [ + "form_urlencoded", + "serde", + "serde_derive", +] + [[package]] name = "quote" version = "1.0.21" @@ -1041,6 +1141,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1118,6 +1230,21 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "tokio" version = "1.22.0" @@ -1252,18 +1379,44 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + [[package]] name = "unicode-ident" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "untrusted" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "urlencoding" version = "2.1.2" diff --git a/rust-1.65/Cargo.toml b/rust-1.65/Cargo.toml index 6c455eb..57b38c0 100644 --- a/rust-1.65/Cargo.toml +++ b/rust-1.65/Cargo.toml @@ -10,6 +10,6 @@ tokio = { version = "1", features = ["full"] } serde_json = "1" serde = "1" log = "0.4" -lambda_runtime = "0.7.1" +lambda_http = "0.7.1" aws-sdk-dynamodb = "0.21.0" aws-config = "0.51.0" diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index ec1c807..e666684 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,18 +1,43 @@ -use lambda_runtime::{service_fn, LambdaEvent, Error}; -use serde_json::{json, Value}; +use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; +use lambda_http::http::HeaderValue; #[tokio::main] async fn main() -> Result<(), Error> { - let func = service_fn(func); - lambda_runtime::run(func).await?; - Ok(()) + run(service_fn(function_handler)).await } -async fn func(event: LambdaEvent) -> Result { - let (event, _context) = event.into_parts(); +async fn function_handler(request: Request) -> Result { + if !check_content_type(&request) { + return Ok(make_bad_request()); + } - Ok(json!({ - "statusCode": 200, - "body": "hello world" - })) + + Ok( + Response::builder() + .status(StatusCode::OK) + .body( + request + .body() + .clone() + ) + .unwrap() + ) +} + +fn check_content_type(request: &Request) -> bool { + request + .headers() + .get("Content-Type") + .map_or(false, is_application_json) +} + +fn is_application_json(header: &HeaderValue) -> bool { + header.as_bytes() == "application/json".as_bytes() +} + +fn make_bad_request() -> Response { + Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::Empty) + .unwrap() } From 8dc7dcb3b5a59d74bda04d7a516949309902054d Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:03:09 +0300 Subject: [PATCH 06/13] body text --- rust-1.65/src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index e666684..8b60830 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -11,15 +11,16 @@ async fn function_handler(request: Request) -> Result return Ok(make_bad_request()); } + let body_text_opt = get_body_text(&request); + if body_text_opt.is_none() { + return Ok(make_bad_request()); + } + let body_text = body_text_opt.unwrap(); Ok( Response::builder() .status(StatusCode::OK) - .body( - request - .body() - .clone() - ) + .body(Body::Text(body_text)) .unwrap() ) } @@ -41,3 +42,10 @@ fn make_bad_request() -> Response { .body(Body::Empty) .unwrap() } + +fn get_body_text(request: &Request) -> Option { + match request.body() { + Body::Text(body) => Some(body.clone()), + _ => None + } +} From e442d724b7b1ba21107d07dd720c345faa9767dd Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Tue, 29 Nov 2022 00:27:42 +0300 Subject: [PATCH 07/13] iteration struct --- rust-1.65/src/iteration.rs | 29 +++++++++++++++++++++++++++++ rust-1.65/src/main.rs | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 rust-1.65/src/iteration.rs diff --git a/rust-1.65/src/iteration.rs b/rust-1.65/src/iteration.rs new file mode 100644 index 0000000..acc3a07 --- /dev/null +++ b/rust-1.65/src/iteration.rs @@ -0,0 +1,29 @@ +use serde::{Deserialize, Serialize}; + +const LANG: &str = "rust-1.65"; + + +pub struct Iteration<'a> { + lang_case: &'a str, + iteration: u64, + raw_event: String, +} + +#[derive(Serialize, Deserialize)] +struct IterationInner { + iteration: u64, +} + + +impl TryFrom<&String> for Iteration<'static> { + type Error = serde_json::Error; + + fn try_from(value: &String) -> Result { + serde_json::from_str::(value.as_str()) + .map(|item| Iteration { + lang_case: LANG, + iteration: item.iteration, + raw_event: value.clone(), + }) + } +} diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index 8b60830..52ac61d 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,5 +1,9 @@ +mod iteration; + use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; use lambda_http::http::HeaderValue; +use crate::iteration::Iteration; + #[tokio::main] async fn main() -> Result<(), Error> { @@ -17,6 +21,12 @@ async fn function_handler(request: Request) -> Result } let body_text = body_text_opt.unwrap(); + let iteration_wrapped = Iteration::try_from(&body_text); + if iteration_wrapped.is_err() { + return Ok(make_bad_request()); + } + let iteration = iteration_wrapped.unwrap(); + Ok( Response::builder() .status(StatusCode::OK) From e6a2e76ea31867af85bf425628264471cd393e9a Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Tue, 29 Nov 2022 02:12:46 +0300 Subject: [PATCH 08/13] store --- rust-1.65/src/iteration.rs | 12 +-- rust-1.65/src/main.rs | 1 + rust-1.65/src/store.rs | 145 +++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 rust-1.65/src/store.rs diff --git a/rust-1.65/src/iteration.rs b/rust-1.65/src/iteration.rs index acc3a07..4e6b4ce 100644 --- a/rust-1.65/src/iteration.rs +++ b/rust-1.65/src/iteration.rs @@ -3,10 +3,10 @@ use serde::{Deserialize, Serialize}; const LANG: &str = "rust-1.65"; -pub struct Iteration<'a> { - lang_case: &'a str, - iteration: u64, - raw_event: String, +pub struct Iteration { + pub lang_case: String, + pub iteration: u64, + pub raw_event: String, } #[derive(Serialize, Deserialize)] @@ -15,13 +15,13 @@ struct IterationInner { } -impl TryFrom<&String> for Iteration<'static> { +impl TryFrom<&String> for Iteration { type Error = serde_json::Error; fn try_from(value: &String) -> Result { serde_json::from_str::(value.as_str()) .map(|item| Iteration { - lang_case: LANG, + lang_case: LANG.parse().unwrap(), iteration: item.iteration, raw_event: value.clone(), }) diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index 52ac61d..c9c3baa 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,4 +1,5 @@ mod iteration; +mod store; use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; use lambda_http::http::HeaderValue; diff --git a/rust-1.65/src/store.rs b/rust-1.65/src/store.rs new file mode 100644 index 0000000..5009e6a --- /dev/null +++ b/rust-1.65/src/store.rs @@ -0,0 +1,145 @@ +use std::collections::HashMap; +use aws_sdk_dynamodb::{Client}; +use aws_sdk_dynamodb::error::{GetItemError, PutItemError}; +use aws_sdk_dynamodb::model::AttributeValue; +use aws_sdk_dynamodb::output::{GetItemOutput, PutItemOutput}; +use aws_sdk_dynamodb::types::SdkError; +use crate::iteration::Iteration; + +enum PutIterationErrors { + TableNameNotSet, + SaveError(SdkError), +} + +pub async fn add_iteration(client: &Client, iteration: &Iteration) -> Result { + let table_name = std::env::var("TABLE"); + if table_name.is_err() { + return Err(PutIterationErrors::TableNameNotSet); + } + + let lang_case = AttributeValue::S(iteration.lang_case.clone()); + let iteration_n = AttributeValue::N(iteration.iteration.to_string()); + let raw_event = AttributeValue::S(iteration.raw_event.clone()); + + client + .put_item() + .table_name(table_name.unwrap()) + .item("langCase", lang_case) + .item("iteration", iteration_n) + .item("raw_event", raw_event) + .send() + .await + .map_err(|error| PutIterationErrors::SaveError(error)) +} + +enum FindIterationError { + TableNameNotSet, + FindItemError(SdkError), + MapResultError(MapResultError), +} + +pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result { + let table_name = std::env::var("TABLE"); + if table_name.is_err() { + return Err(FindIterationError::TableNameNotSet); + } + + let lang = AttributeValue::S(iteration.lang_case.clone()); + let iteration_n = AttributeValue::N((iteration.iteration - 1).to_string()); + + client + .get_item() + .table_name(table_name.unwrap()) + .key("langCase", lang) + .key("iteration", iteration_n) + .send() + .await + .map_err(|error| FindIterationError::FindItemError(error)) + .and_then(|raw| { + match map_result(raw) { + Ok(val) => Ok(val), + Err(err) => Err(FindIterationError::MapResultError(err)) + } + }) +} + +enum MapResultError { + EmptyOutput, + MapValueError(MapValueError), +} + +fn map_result(output: GetItemOutput) -> Result { + let item = output.item(); + if item.is_none() { + return Err(MapResultError::EmptyOutput); + } + + let lang = get_lang_value(item.unwrap()); + if lang.is_err() { + return Err(MapResultError::MapValueError(lang.err().unwrap())); + } + + let iteration_n = get_iteration_value(item.unwrap()); + if iteration_n.is_err() { + return Err(MapResultError::MapValueError(iteration_n.err().unwrap())); + } + + let raw_event = get_raw_event_value(item.unwrap()); + if raw_event.is_err() { + return Err(MapResultError::MapValueError(raw_event.err().unwrap())); + } + + Ok(Iteration { + lang_case: lang.unwrap(), + raw_event: raw_event.unwrap(), + iteration: iteration_n.unwrap(), + }) +} + +#[derive(Debug)] +enum MapValueError { + KeyMissing(String), + UnexpectedReturnValueType(String), + ParsingValueError(String), +} + +fn get_lang_value(result: &HashMap) -> Result { + let lang_value = result.get("langCase"); + if lang_value.is_none() { + return Err(MapValueError::KeyMissing("langCase".parse().unwrap())); + } + + match lang_value.unwrap() { + AttributeValue::S(val) => Ok(val.clone()), + _ => Err(MapValueError::UnexpectedReturnValueType("langCase".parse().unwrap())) + } +} + +fn get_iteration_value(result: &HashMap) -> Result { + let lang_value = result.get("iteration"); + if lang_value.is_none() { + return Err(MapValueError::KeyMissing("iteration".parse().unwrap())); + } + + match lang_value.unwrap() { + AttributeValue::N(val) => { + match val.parse::() { + Ok(value) => Ok(value), + Err(_) => Err(MapValueError::ParsingValueError("iteration".parse().unwrap())) + } + } + _ => Err(MapValueError::UnexpectedReturnValueType("iteration".parse().unwrap())) + } +} + +fn get_raw_event_value(result: &HashMap) -> Result { + let lang_value = result.get("raw_event"); + if lang_value.is_none() { + return Err(MapValueError::KeyMissing("raw_event".parse().unwrap())); + } + + match lang_value.unwrap() { + AttributeValue::S(val) => Ok(val.clone()), + _ => Err(MapValueError::UnexpectedReturnValueType("raw_event".parse().unwrap())) + } +} From 08e8052b3ea4d5b1410b298dd027a6544a40df8c Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Tue, 29 Nov 2022 03:10:38 +0300 Subject: [PATCH 09/13] done not tested --- rust-1.65/Cargo.toml | 4 ++++ rust-1.65/src/iteration.rs | 2 +- rust-1.65/src/main.rs | 39 ++++++++++++++++++++++++++++++-------- rust-1.65/src/store.rs | 35 +++++++++++++++++----------------- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/rust-1.65/Cargo.toml b/rust-1.65/Cargo.toml index 57b38c0..e5bf235 100644 --- a/rust-1.65/Cargo.toml +++ b/rust-1.65/Cargo.toml @@ -13,3 +13,7 @@ log = "0.4" lambda_http = "0.7.1" aws-sdk-dynamodb = "0.21.0" aws-config = "0.51.0" + +[profile.release] +strip = true +lto = true diff --git a/rust-1.65/src/iteration.rs b/rust-1.65/src/iteration.rs index 4e6b4ce..2474c58 100644 --- a/rust-1.65/src/iteration.rs +++ b/rust-1.65/src/iteration.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; const LANG: &str = "rust-1.65"; - +#[derive(Serialize, Deserialize)] pub struct Iteration { pub lang_case: String, pub iteration: u64, diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index c9c3baa..ea03e60 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,17 +1,22 @@ mod iteration; mod store; +use aws_sdk_dynamodb::Client; use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; use lambda_http::http::HeaderValue; use crate::iteration::Iteration; +use crate::store::{add_iteration, find_iteration}; +use serde::Serialize; #[tokio::main] async fn main() -> Result<(), Error> { - run(service_fn(function_handler)).await + let config = aws_config::load_from_env().await; + let client = Client::new(&config); + run(service_fn(|request| function_handler(request, &client))).await } -async fn function_handler(request: Request) -> Result { +async fn function_handler(request: Request, client: &Client) -> Result { if !check_content_type(&request) { return Ok(make_bad_request()); } @@ -28,12 +33,30 @@ async fn function_handler(request: Request) -> Result } let iteration = iteration_wrapped.unwrap(); - Ok( - Response::builder() - .status(StatusCode::OK) - .body(Body::Text(body_text)) - .unwrap() - ) + let added_item = add_iteration(client, &iteration).await; + if added_item.is_err() { + return Ok(make_bad_request()); + } + + let prev_item = find_iteration(client, &iteration).await; + if prev_item.is_err() { + return Ok(make_bad_request()); + } + + match prev_item.unwrap() { + None => Ok(make_success_response(iteration).unwrap()), + Some(iteration) => Ok(make_success_response(iteration).unwrap()) + } +} + +fn make_success_response(body: impl Serialize) -> Result, serde_json::Error> { + serde_json::to_string(&body) + .map(|serialized| { + Response::builder() + .status(StatusCode::OK) + .body(Body::Text(serialized)) + .unwrap() + }) } fn check_content_type(request: &Request) -> bool { diff --git a/rust-1.65/src/store.rs b/rust-1.65/src/store.rs index 5009e6a..acbd3e1 100644 --- a/rust-1.65/src/store.rs +++ b/rust-1.65/src/store.rs @@ -2,11 +2,11 @@ use std::collections::HashMap; use aws_sdk_dynamodb::{Client}; use aws_sdk_dynamodb::error::{GetItemError, PutItemError}; use aws_sdk_dynamodb::model::AttributeValue; -use aws_sdk_dynamodb::output::{GetItemOutput, PutItemOutput}; +use aws_sdk_dynamodb::output::{PutItemOutput}; use aws_sdk_dynamodb::types::SdkError; use crate::iteration::Iteration; -enum PutIterationErrors { +pub enum PutIterationErrors { TableNameNotSet, SaveError(SdkError), } @@ -32,13 +32,14 @@ pub async fn add_iteration(client: &Client, iteration: &Iteration) -> Result), MapResultError(MapResultError), } -pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result { +pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result, FindIterationError> { let table_name = std::env::var("TABLE"); if table_name.is_err() { return Err(FindIterationError::TableNameNotSet); @@ -56,35 +57,33 @@ pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result Ok(val), + if raw.item().is_none() { + return Ok(None); + } + match map_result(raw.item().unwrap()) { + Ok(val) => Ok(Some(val)), Err(err) => Err(FindIterationError::MapResultError(err)) } }) } -enum MapResultError { - EmptyOutput, +#[derive(Debug)] +pub enum MapResultError { MapValueError(MapValueError), } -fn map_result(output: GetItemOutput) -> Result { - let item = output.item(); - if item.is_none() { - return Err(MapResultError::EmptyOutput); - } - - let lang = get_lang_value(item.unwrap()); +fn map_result(item: &HashMap) -> Result { + let lang = get_lang_value(item); if lang.is_err() { return Err(MapResultError::MapValueError(lang.err().unwrap())); } - let iteration_n = get_iteration_value(item.unwrap()); + let iteration_n = get_iteration_value(item); if iteration_n.is_err() { return Err(MapResultError::MapValueError(iteration_n.err().unwrap())); } - let raw_event = get_raw_event_value(item.unwrap()); + let raw_event = get_raw_event_value(item); if raw_event.is_err() { return Err(MapResultError::MapValueError(raw_event.err().unwrap())); } @@ -97,7 +96,7 @@ fn map_result(output: GetItemOutput) -> Result { } #[derive(Debug)] -enum MapValueError { +pub enum MapValueError { KeyMissing(String), UnexpectedReturnValueType(String), ParsingValueError(String), From 66be74263ff1c9075ce0af5d8384214363dfe8d5 Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 4 Dec 2022 04:57:15 +0300 Subject: [PATCH 10/13] to_bad_response --- rust-1.65/src/main.rs | 98 +++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 22 deletions(-) diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index ea03e60..064a229 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -16,31 +16,48 @@ async fn main() -> Result<(), Error> { run(service_fn(|request| function_handler(request, &client))).await } -async fn function_handler(request: Request, client: &Client) -> Result { - if !check_content_type(&request) { - return Ok(make_bad_request()); - } +macro_rules! to_bad_response { + ($lit:ident, $expr:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); + + return Ok(error.to_bad_response()); + } + + let $lit = $expr.unwrap(); + }; + ($expr:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); - let body_text_opt = get_body_text(&request); - if body_text_opt.is_none() { - return Ok(make_bad_request()); + return Ok(error.to_bad_response()); + } } - let body_text = body_text_opt.unwrap(); +} + +#[derive(Debug)] +struct BadIterationParsing; - let iteration_wrapped = Iteration::try_from(&body_text); - if iteration_wrapped.is_err() { - return Ok(make_bad_request()); +impl ToBadResponse for BadIterationParsing { + fn to_bad_response(&self) -> Response { + make_bad_response() } - let iteration = iteration_wrapped.unwrap(); +} + + +async fn function_handler(request: Request, client: &Client) -> Result { + to_bad_response!(check_content_type(&request)); + to_bad_response!(body_text, get_body_text(&request)); + to_bad_response!(iteration, Iteration::try_from(&body_text).map_err(|_| BadIterationParsing)); let added_item = add_iteration(client, &iteration).await; if added_item.is_err() { - return Ok(make_bad_request()); + return Ok(make_bad_response()); } let prev_item = find_iteration(client, &iteration).await; if prev_item.is_err() { - return Ok(make_bad_request()); + return Ok(make_bad_response()); } match prev_item.unwrap() { @@ -59,27 +76,64 @@ fn make_success_response(body: impl Serialize) -> Result, serde_j }) } -fn check_content_type(request: &Request) -> bool { - request +trait ToBadResponse { + fn to_bad_response(&self) -> Response; +} + +#[derive(Debug)] +enum CheckContentTypeErrors { + MissingContentType, + ContentTypeNotSupported, +} + +impl ToBadResponse for CheckContentTypeErrors { + fn to_bad_response(&self) -> Response { + match self { + CheckContentTypeErrors::MissingContentType => make_bad_response(), + CheckContentTypeErrors::ContentTypeNotSupported => make_bad_response(), + } + } +} + +fn check_content_type(request: &Request) -> Result { + let value = request .headers() - .get("Content-Type") - .map_or(false, is_application_json) + .get("Content-Type"); + + if value.is_none() { + return Err(CheckContentTypeErrors::MissingContentType); + } + + if !is_application_json(value.unwrap()) { + return Err(CheckContentTypeErrors::ContentTypeNotSupported); + } + + Ok(true) } fn is_application_json(header: &HeaderValue) -> bool { header.as_bytes() == "application/json".as_bytes() } -fn make_bad_request() -> Response { +fn make_bad_response() -> Response { Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::Empty) .unwrap() } -fn get_body_text(request: &Request) -> Option { +#[derive(Debug)] +struct GetBodyTextError; + +impl ToBadResponse for GetBodyTextError { + fn to_bad_response(&self) -> Response { + make_bad_response() + } +} + +fn get_body_text(request: &Request) -> Result { match request.body() { - Body::Text(body) => Some(body.clone()), - _ => None + Body::Text(body) => Ok(body.clone()), + _ => Err(GetBodyTextError) } } From 462a528bbd6072be9178a7ad4c1fcb36be6c9e97 Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 4 Dec 2022 17:04:51 +0100 Subject: [PATCH 11/13] validate_request --- rust-1.65/src/main.rs | 36 +++++++++++++++++++++++++++- rust-1.65/src/validate_request.rs | 40 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 rust-1.65/src/validate_request.rs diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index 064a229..605b60a 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,12 +1,17 @@ mod iteration; mod store; +mod validate_request; +use std::fmt::Display; use aws_sdk_dynamodb::Client; use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; use lambda_http::http::HeaderValue; use crate::iteration::Iteration; use crate::store::{add_iteration, find_iteration}; +use crate::validate_request::validate_request; + use serde::Serialize; +use serde_json::json; #[tokio::main] @@ -44,9 +49,38 @@ impl ToBadResponse for BadIterationParsing { } } +fn format_body(err: &impl Display) -> Body { + Body::Text(json!({ + "error_message": err.to_string() + }).to_string()) +} + +fn build_response(status_code: &StatusCode, err: &impl Display) -> Response { + Response::builder() + .status(status_code) + .body(format_body(err)) + .unwrap() +} + +macro_rules! bad_response { + ($expr:expr, $status_code:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); + return Ok(build_response(&$status_code, &error)); + } + }; + ($lit:ident, $expr:expr, $status_code:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); + return Ok(build_response(&$status_code, &error)); + } + let $lit = $expr.unwrap(); + }; +} async fn function_handler(request: Request, client: &Client) -> Result { - to_bad_response!(check_content_type(&request)); + bad_response!(validate_request(&request), StatusCode::BAD_REQUEST); + to_bad_response!(body_text, get_body_text(&request)); to_bad_response!(iteration, Iteration::try_from(&body_text).map_err(|_| BadIterationParsing)); diff --git a/rust-1.65/src/validate_request.rs b/rust-1.65/src/validate_request.rs new file mode 100644 index 0000000..88f56cb --- /dev/null +++ b/rust-1.65/src/validate_request.rs @@ -0,0 +1,40 @@ +use std::fmt::{Display, Formatter, write}; +use lambda_http::http::HeaderValue; +use lambda_http::Request; + +pub enum ValidationError<'a> { + MissingContentType, + ContentTypeNotSupported(&'a HeaderValue), +} + +impl<'a> Display for ValidationError<'a> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ValidationError::ContentTypeNotSupported( header) => write!(f, " `{:?}` content type not supported", header.as_bytes()), + ValidationError::MissingContentType => write!(f, "missing `Content-Type` header") + } + } +} + + + +pub fn validate_request(request: &Request) -> Result { + check_content_type(request) +} + + +fn check_content_type(request: &Request) -> Result { + let value = request + .headers() + .get("Content-Type"); + + if value.is_none() { + return Err(ValidationError::MissingContentType); + } + + if value.unwrap().as_bytes() != "application/json".as_bytes() { + return Err(ValidationError::ContentTypeNotSupported(value.unwrap())) + } + + Ok(true) +} From e77a486533ae6ae84c97e94c25cfb05def501d5b Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 4 Dec 2022 17:13:25 +0100 Subject: [PATCH 12/13] body_string --- rust-1.65/src/body_string.rs | 18 ++++++++++++++++++ rust-1.65/src/main.rs | 6 ++++-- rust-1.65/src/validate_request.rs | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 rust-1.65/src/body_string.rs diff --git a/rust-1.65/src/body_string.rs b/rust-1.65/src/body_string.rs new file mode 100644 index 0000000..0beddc0 --- /dev/null +++ b/rust-1.65/src/body_string.rs @@ -0,0 +1,18 @@ +use std::fmt::{Display, Formatter}; +use lambda_http::{Request, Body}; + +#[derive(Debug)] +pub struct GetBodyTextError; + +impl Display for GetBodyTextError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "request body should be string") + } +} + +pub fn get_body_string(request: &Request) -> Result<&String, GetBodyTextError> { + match request.body() { + Body::Text(value) => Ok(value), + _ => Err(GetBodyTextError) + } +} diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index 605b60a..95898b4 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -1,6 +1,7 @@ mod iteration; mod store; mod validate_request; +mod body_string; use std::fmt::Display; use aws_sdk_dynamodb::Client; @@ -9,6 +10,7 @@ use lambda_http::http::HeaderValue; use crate::iteration::Iteration; use crate::store::{add_iteration, find_iteration}; use crate::validate_request::validate_request; +use crate::body_string::get_body_string; use serde::Serialize; use serde_json::json; @@ -80,9 +82,9 @@ macro_rules! bad_response { async fn function_handler(request: Request, client: &Client) -> Result { bad_response!(validate_request(&request), StatusCode::BAD_REQUEST); + bad_response!(body_string, get_body_string(&request), StatusCode::BAD_REQUEST); - to_bad_response!(body_text, get_body_text(&request)); - to_bad_response!(iteration, Iteration::try_from(&body_text).map_err(|_| BadIterationParsing)); + to_bad_response!(iteration, Iteration::try_from(body_string).map_err(|_| BadIterationParsing)); let added_item = add_iteration(client, &iteration).await; if added_item.is_err() { diff --git a/rust-1.65/src/validate_request.rs b/rust-1.65/src/validate_request.rs index 88f56cb..3fa7ef5 100644 --- a/rust-1.65/src/validate_request.rs +++ b/rust-1.65/src/validate_request.rs @@ -1,4 +1,4 @@ -use std::fmt::{Display, Formatter, write}; +use std::fmt::{Display, Formatter}; use lambda_http::http::HeaderValue; use lambda_http::Request; From efccca697363a9e4a28570324f4eb09ad8f2cc24 Mon Sep 17 00:00:00 2001 From: ghost <78723252+DmitriyFirsov@users.noreply.github.com> Date: Sun, 4 Dec 2022 18:34:14 +0100 Subject: [PATCH 13/13] refactoring --- rust-1.65/src/bad_response.rs | 34 ++++++++ rust-1.65/src/main.rs | 157 +++------------------------------- rust-1.65/src/store.rs | 77 ++++++++++------- 3 files changed, 91 insertions(+), 177 deletions(-) create mode 100644 rust-1.65/src/bad_response.rs diff --git a/rust-1.65/src/bad_response.rs b/rust-1.65/src/bad_response.rs new file mode 100644 index 0000000..5a1ea0c --- /dev/null +++ b/rust-1.65/src/bad_response.rs @@ -0,0 +1,34 @@ +use serde_json::json; +use lambda_http::{Response, Body, http::StatusCode}; +use std::fmt::Display; + +fn format_body(err: &impl Display) -> Body { + Body::Text(json!({ + "error_message": err.to_string() + }).to_string()) +} + +pub fn build_response(status_code: &StatusCode, err: &impl Display) -> Response { + Response::builder() + .status(status_code) + .header("Content-Type", "application/json") + .body(format_body(err)) + .unwrap() +} + +#[macro_export] +macro_rules! bad_response { + ($expr:expr, $status_code:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); + return Ok(build_response(&$status_code, &error)); + } + }; + ($lit:ident, $expr:expr, $status_code:expr) => { + if $expr.is_err() { + let error = $expr.err().unwrap(); + return Ok(build_response(&$status_code, &error)); + } + let $lit = $expr.unwrap(); + }; +} diff --git a/rust-1.65/src/main.rs b/rust-1.65/src/main.rs index 95898b4..955a58a 100644 --- a/rust-1.65/src/main.rs +++ b/rust-1.65/src/main.rs @@ -2,19 +2,18 @@ mod iteration; mod store; mod validate_request; mod body_string; +#[macro_use] +mod bad_response; -use std::fmt::Display; use aws_sdk_dynamodb::Client; use lambda_http::{run, http::StatusCode, service_fn, Error, IntoResponse, Request, Response, Body}; -use lambda_http::http::HeaderValue; use crate::iteration::Iteration; use crate::store::{add_iteration, find_iteration}; use crate::validate_request::validate_request; use crate::body_string::get_body_string; - use serde::Serialize; -use serde_json::json; +use crate::bad_response::*; #[tokio::main] async fn main() -> Result<(), Error> { @@ -23,153 +22,23 @@ async fn main() -> Result<(), Error> { run(service_fn(|request| function_handler(request, &client))).await } -macro_rules! to_bad_response { - ($lit:ident, $expr:expr) => { - if $expr.is_err() { - let error = $expr.err().unwrap(); - - return Ok(error.to_bad_response()); - } - - let $lit = $expr.unwrap(); - }; - ($expr:expr) => { - if $expr.is_err() { - let error = $expr.err().unwrap(); - - return Ok(error.to_bad_response()); - } - } -} - -#[derive(Debug)] -struct BadIterationParsing; - -impl ToBadResponse for BadIterationParsing { - fn to_bad_response(&self) -> Response { - make_bad_response() - } -} - -fn format_body(err: &impl Display) -> Body { - Body::Text(json!({ - "error_message": err.to_string() - }).to_string()) -} - -fn build_response(status_code: &StatusCode, err: &impl Display) -> Response { - Response::builder() - .status(status_code) - .body(format_body(err)) - .unwrap() -} - -macro_rules! bad_response { - ($expr:expr, $status_code:expr) => { - if $expr.is_err() { - let error = $expr.err().unwrap(); - return Ok(build_response(&$status_code, &error)); - } - }; - ($lit:ident, $expr:expr, $status_code:expr) => { - if $expr.is_err() { - let error = $expr.err().unwrap(); - return Ok(build_response(&$status_code, &error)); - } - let $lit = $expr.unwrap(); - }; -} - async fn function_handler(request: Request, client: &Client) -> Result { bad_response!(validate_request(&request), StatusCode::BAD_REQUEST); bad_response!(body_string, get_body_string(&request), StatusCode::BAD_REQUEST); + bad_response!(iteration, Iteration::try_from(body_string), StatusCode::BAD_REQUEST); + bad_response!(add_iteration(client, &iteration).await, StatusCode::BAD_REQUEST); + bad_response!(prev_item, find_iteration(client, &iteration).await, StatusCode::BAD_REQUEST); - to_bad_response!(iteration, Iteration::try_from(body_string).map_err(|_| BadIterationParsing)); - - let added_item = add_iteration(client, &iteration).await; - if added_item.is_err() { - return Ok(make_bad_response()); - } - - let prev_item = find_iteration(client, &iteration).await; - if prev_item.is_err() { - return Ok(make_bad_response()); - } - - match prev_item.unwrap() { - None => Ok(make_success_response(iteration).unwrap()), - Some(iteration) => Ok(make_success_response(iteration).unwrap()) + match prev_item { + None => Ok(make_success_response(&iteration)), + Some(iteration) => Ok(make_success_response(&iteration)) } } -fn make_success_response(body: impl Serialize) -> Result, serde_json::Error> { - serde_json::to_string(&body) - .map(|serialized| { - Response::builder() - .status(StatusCode::OK) - .body(Body::Text(serialized)) - .unwrap() - }) -} - -trait ToBadResponse { - fn to_bad_response(&self) -> Response; -} - -#[derive(Debug)] -enum CheckContentTypeErrors { - MissingContentType, - ContentTypeNotSupported, -} - -impl ToBadResponse for CheckContentTypeErrors { - fn to_bad_response(&self) -> Response { - match self { - CheckContentTypeErrors::MissingContentType => make_bad_response(), - CheckContentTypeErrors::ContentTypeNotSupported => make_bad_response(), - } - } -} - -fn check_content_type(request: &Request) -> Result { - let value = request - .headers() - .get("Content-Type"); - - if value.is_none() { - return Err(CheckContentTypeErrors::MissingContentType); - } - - if !is_application_json(value.unwrap()) { - return Err(CheckContentTypeErrors::ContentTypeNotSupported); - } - - Ok(true) -} - -fn is_application_json(header: &HeaderValue) -> bool { - header.as_bytes() == "application/json".as_bytes() -} - -fn make_bad_response() -> Response { +fn make_success_response(body: &impl Serialize) -> Response { Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::Empty) + .status(StatusCode::OK) + .header("Content-Type", "application/json") + .body(Body::Text(serde_json::to_string(body).unwrap())) .unwrap() } - -#[derive(Debug)] -struct GetBodyTextError; - -impl ToBadResponse for GetBodyTextError { - fn to_bad_response(&self) -> Response { - make_bad_response() - } -} - -fn get_body_text(request: &Request) -> Result { - match request.body() { - Body::Text(body) => Ok(body.clone()), - _ => Err(GetBodyTextError) - } -} diff --git a/rust-1.65/src/store.rs b/rust-1.65/src/store.rs index acbd3e1..a7a06ad 100644 --- a/rust-1.65/src/store.rs +++ b/rust-1.65/src/store.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt::{Display, Formatter}; use aws_sdk_dynamodb::{Client}; use aws_sdk_dynamodb::error::{GetItemError, PutItemError}; use aws_sdk_dynamodb::model::AttributeValue; @@ -11,6 +12,15 @@ pub enum PutIterationErrors { SaveError(SdkError), } +impl Display for PutIterationErrors { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + PutIterationErrors::TableNameNotSet => write!(f, "Table name env variable is not set"), + PutIterationErrors::SaveError(sdk_error) => write!(f, "Saving item iteration error {}", sdk_error), + } + } +} + pub async fn add_iteration(client: &Client, iteration: &Iteration) -> Result { let table_name = std::env::var("TABLE"); if table_name.is_err() { @@ -36,7 +46,17 @@ pub async fn add_iteration(client: &Client, iteration: &Iteration) -> Result), - MapResultError(MapResultError), + MapResultError(MapValueError), +} + +impl Display for FindIterationError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + FindIterationError::TableNameNotSet => write!(f, "Table name env variable is not set"), + FindIterationError::FindItemError(sdk_error) => write!(f, "previous item is not founded {}", sdk_error), + FindIterationError::MapResultError(error) => write!(f, "map result error {}", error) + } + } } pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result, FindIterationError> { @@ -57,7 +77,7 @@ pub async fn find_iteration(client: &Client, iteration: &Iteration) -> Result Result) -> Result { - let lang = get_lang_value(item); - if lang.is_err() { - return Err(MapResultError::MapValueError(lang.err().unwrap())); - } - - let iteration_n = get_iteration_value(item); - if iteration_n.is_err() { - return Err(MapResultError::MapValueError(iteration_n.err().unwrap())); - } - - let raw_event = get_raw_event_value(item); - if raw_event.is_err() { - return Err(MapResultError::MapValueError(raw_event.err().unwrap())); - } +fn map_result(item: &HashMap) -> Result { Ok(Iteration { - lang_case: lang.unwrap(), - raw_event: raw_event.unwrap(), - iteration: iteration_n.unwrap(), + lang_case: get_lang_value(item)?, + raw_event: get_raw_event_value(item)?.clone(), + iteration: get_iteration_value(item)?, }) } #[derive(Debug)] pub enum MapValueError { KeyMissing(String), - UnexpectedReturnValueType(String), - ParsingValueError(String), + UnexpectedReturnValueType(String, AttributeValue), + ParsingU64Error(String), +} + +impl Display for MapValueError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + MapValueError::KeyMissing(key) => write!(f, "missing {} from dynamodb response", key), + MapValueError::UnexpectedReturnValueType(key, _) => write!(f, "unexpected {} value type returned from dynamodb", key), + MapValueError::ParsingU64Error(key) => write!(f, "error parsing {}", key) + } + } } fn get_lang_value(result: &HashMap) -> Result { @@ -110,7 +121,7 @@ fn get_lang_value(result: &HashMap) -> Result Ok(val.clone()), - _ => Err(MapValueError::UnexpectedReturnValueType("langCase".parse().unwrap())) + _ => Err(MapValueError::UnexpectedReturnValueType("langCase".parse().unwrap(), lang_value.unwrap().clone())) } } @@ -124,21 +135,21 @@ fn get_iteration_value(result: &HashMap) -> Result { match val.parse::() { Ok(value) => Ok(value), - Err(_) => Err(MapValueError::ParsingValueError("iteration".parse().unwrap())) + Err(_) => Err(MapValueError::ParsingU64Error("iteration".parse().unwrap())) } } - _ => Err(MapValueError::UnexpectedReturnValueType("iteration".parse().unwrap())) + _ => Err(MapValueError::UnexpectedReturnValueType("iteration".parse().unwrap(), lang_value.unwrap().clone())) } } -fn get_raw_event_value(result: &HashMap) -> Result { +fn get_raw_event_value(result: &HashMap) -> Result<&String, MapValueError> { let lang_value = result.get("raw_event"); if lang_value.is_none() { return Err(MapValueError::KeyMissing("raw_event".parse().unwrap())); } match lang_value.unwrap() { - AttributeValue::S(val) => Ok(val.clone()), - _ => Err(MapValueError::UnexpectedReturnValueType("raw_event".parse().unwrap())) + AttributeValue::S(val) => Ok(val), + _ => Err(MapValueError::UnexpectedReturnValueType("raw_event".parse().unwrap(), lang_value.unwrap().clone())) } }