| 84 | } |
| 85 | |
| 86 | void create_function(Aws::String const& function_name, Aws::String const& handler_name) |
| 87 | { |
| 88 | Model::CreateFunctionRequest create_function_request; |
| 89 | create_function_request.SetHandler(handler_name); |
| 90 | create_function_request.SetFunctionName(function_name); |
| 91 | // I ran into eventual-consistency issues when creating the role dynamically as part of the test. |
| 92 | auto exec_role = Aws::Environment::GetEnv("LAMBDA_TEST_ROLE"); |
| 93 | if (exec_role.empty()) { |
| 94 | exec_role = "integration-tests"; |
| 95 | } |
| 96 | create_function_request.SetRole(get_role_arn(exec_role)); |
| 97 | |
| 98 | struct stat s; |
| 99 | auto rc = stat(ZIP_FILE_PATH, &s); |
| 100 | ASSERT_EQ(rc, 0) << std::string("file does not exist: ") + ZIP_FILE_PATH; |
| 101 | Aws::Utils::CryptoBuffer zip_file_bytes(s.st_size); |
| 102 | auto* zip_file = fopen(ZIP_FILE_PATH, "r"); |
| 103 | fread(zip_file_bytes.GetUnderlyingData(), sizeof(unsigned char), s.st_size, zip_file); |
| 104 | fclose(zip_file); |
| 105 | |
| 106 | Model::FunctionCode funcode; |
| 107 | funcode.SetZipFile(std::move(zip_file_bytes)); |
| 108 | create_function_request.SetCode(std::move(funcode)); |
| 109 | create_function_request.SetRuntime(Aws::Lambda::Model::Runtime::provided_al2); |
| 110 | |
| 111 | std::vector<Aws::Lambda::Model::Architecture> lambda_architectures = {Aws::Lambda::Model::Architecture::x86_64}; |
| 112 | #ifdef __aarch64__ |
| 113 | lambda_architectures[0] = Aws::Lambda::Model::Architecture::arm64; |
| 114 | #endif |
| 115 | create_function_request.SetArchitectures(lambda_architectures); |
| 116 | |
| 117 | auto outcome = m_lambda_client.CreateFunction(create_function_request); |
| 118 | ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << function_name; |
| 119 | |
| 120 | // work around Lambda function pending creation state |
| 121 | sleep(5); |
| 122 | } |
| 123 | |
| 124 | void delete_function(Aws::String const& function_name, bool assert = true) |
| 125 | { |