Skill 3.1.1

Manage dependencies for code modules (for example, environment variables, configuration files, container images) within packages.

Key Concepts

Libraries are declared in a dependency file such as requirements.txt, package.json or pom.xml and installed during the build, so the artifact is reproducible. For Lambda, dependencies go into the .zip package, into layers shared between functions, or into a container image built from an AWS base image. Native libraries must be built for the Lambda environment (Amazon Linux and the right architecture), which sam build --use-container handles.

Environment-specific values should not be baked into the artifact. Pass them as environment variables, read them from Parameter Store, Secrets Manager or AWS AppConfig, or supply them as CloudFormation parameters, so the same artifact can be promoted from test to production unchanged. AWS CodeArtifact hosts private package repositories for internal libraries.

Build and deployment specification files live at the root by default: buildspec.yml for CodeBuild, appspec.yml for CodeDeploy on EC2, and template.yaml for AWS SAM. Elastic Beanstalk source bundles keep configuration in .ebextensions/ and platform hooks in .platform/, and the bundle's top level must contain the application files, not a parent folder.

For Lambda, the handler path must match the file layout inside the package, and layer content must sit in runtime-specific folders such as python/ or nodejs/node_modules/ to be found on the path. A SAM project usually keeps each function's code in its own folder referenced by CodeUri.

For Lambda you set memory from 128 MB to 10,240 MB, which also determines CPU (up to six vCPUs), plus ephemeral storage and the timeout. For ECS you set CPU and memory at the task and container level in the task definition; Fargate supports specific CPU and memory combinations. For EC2 and Elastic Beanstalk you choose instance types sized for the workload.

These requirements should be defined in infrastructure as code (SAM, CloudFormation or CDK) so they are versioned and consistent across environments. CloudWatch metrics such as Lambda duration and max memory used, and CloudWatch Lambda Insights, help right-size them.