/** * Inline Lambda handler code for triggering CodeBuild container image builds. * * This is deployed via lambda.Code.fromInline() as a CloudFormation Custom Resource handler. * It starts a CodeBuild build, polls for completion, and returns the container URI. * * Stored as a string constant (not a standalone .js file) because this library is * consumed as an npm package — __dirname / fromAsset paths won't resolve correctly * in consumer projects. * * Custom Resource properties: * - ProjectName: CodeBuild project name * - SourceBucket/SourceKey: S3 location of the source code * - EcrRegistry: ECR registry URL * - ImageUri: Target image URI (repo:tag) * - DockerfilePath: Path to Dockerfile in the source */ export declare const CONTAINER_BUILD_HANDLER_CODE = "\nconst { CodeBuildClient, StartBuildCommand, BatchGetBuildsCommand } = require('@aws-sdk/client-codebuild');\nconst codebuild = new CodeBuildClient();\n\nexports.handler = async function(event, context) {\n const props = event.ResourceProperties;\n const requestType = event.RequestType;\n\n // Build the response object\n const response = {\n Status: 'SUCCESS',\n PhysicalResourceId: props.ImageUri || 'container-build',\n StackId: event.StackId,\n RequestId: event.RequestId,\n LogicalResourceId: event.LogicalResourceId,\n Data: {},\n };\n\n try {\n if (requestType === 'Delete') {\n response.Data = {};\n await sendResponse(event, response);\n return;\n }\n\n // Start CodeBuild\n const startResult = await codebuild.send(new StartBuildCommand({\n projectName: props.ProjectName,\n sourceTypeOverride: 'S3',\n sourceLocationOverride: props.SourceBucket + '/' + props.SourceKey,\n environmentVariablesOverride: [\n { name: 'ECR_REGISTRY', value: props.EcrRegistry, type: 'PLAINTEXT' },\n { name: 'IMAGE_URI', value: props.ImageUri, type: 'PLAINTEXT' },\n { name: 'DOCKERFILE_PATH', value: props.DockerfilePath, type: 'PLAINTEXT' },\n ],\n }));\n\n const buildId = startResult.build.id;\n console.log('Started build:', buildId);\n\n // Poll until complete (14 minutes max to stay within Lambda's 15-minute timeout)\n const maxWaitMs = 14 * 60 * 1000;\n const start = Date.now();\n while (Date.now() - start < maxWaitMs) {\n const result = await codebuild.send(new BatchGetBuildsCommand({ ids: [buildId] }));\n const build = result.builds[0];\n if (build.buildStatus !== 'IN_PROGRESS') {\n if (build.buildStatus === 'SUCCEEDED') {\n response.Data = { ContainerUri: props.ImageUri };\n await sendResponse(event, response);\n return;\n } else {\n const logsUrl = build.logs && build.logs.deepLink ? build.logs.deepLink : 'Check CloudWatch Logs';\n response.Status = 'FAILED';\n response.Reason = 'CodeBuild build failed. Status: ' + build.buildStatus + '. Logs: ' + logsUrl;\n await sendResponse(event, response);\n return;\n }\n }\n await new Promise(r => setTimeout(r, 10000));\n }\n\n response.Status = 'FAILED';\n response.Reason = 'Build timed out after 14 minutes';\n await sendResponse(event, response);\n } catch (err) {\n response.Status = 'FAILED';\n response.Reason = err.message || 'Unknown error';\n await sendResponse(event, response);\n }\n};\n\nasync function sendResponse(event, response) {\n const https = require('https');\n const responseBody = JSON.stringify(response);\n const parsedUrl = new URL(event.ResponseURL);\n const options = {\n hostname: parsedUrl.hostname,\n port: 443,\n path: parsedUrl.pathname + parsedUrl.search,\n method: 'PUT',\n headers: { 'content-type': '', 'content-length': responseBody.length },\n };\n return new Promise((resolve, reject) => {\n const req = https.request(options, resolve);\n req.on('error', reject);\n req.write(responseBody);\n req.end();\n });\n}\n"; //# sourceMappingURL=container-build-handler.d.ts.map