Aws SAM CLI incorporates BuildKit support for Lambda container images
AWS SAM CLI now supports BuildKit, enhancing the building of container images for Lambda functions with faster, optimized processes. Developers can leverage multi-stage builds, improved caching, and cross-architecture builds.
The AWS Serverless Application Model Command Line Interface (SAM CLI) has introduced support for BuildKit, enhancing the process of building container images from Dockerfiles. This advancement allows for faster and more efficient creation of container images for AWS Lambda functions that are packaged as container images.
SAM CLI is a tool designed to assist developers in building, testing, debugging, and packaging serverless applications locally before deploying them to the AWS Cloud. Previously, developers who packaged Lambda functions as container images lacked access to BuildKit’s advanced build features, which are essential for optimizing images for production environments. With the integration of BuildKit, developers can now leverage multi-stage builds to produce smaller final images devoid of development dependencies, utilize improved caching to minimize rebuild times, and benefit from enhanced parallelization of build steps.
Additionally, BuildKit’s capabilities extend to cross-architecture builds, enabling the creation of container images that target both x86_64 and arm64 (AWS Graviton2) instruction set architectures from a single development machine. Developers can also incorporate Docker secrets during the build process, ensuring that sensitive data such as credentials and API keys remain secure and are not included in the final image layers.
To utilize these new features, developers should download or update SAM CLI to version 1.159.0 or later and apply the –use-buildkit flag when executing the sam build command. This feature functions seamlessly with both Docker and Finch when used with SAM CLI, thereby unlocking the full spectrum of BuildKit capabilities. For further information, developers are encouraged to consult the SAM CLI developer guide.