I am trying to deploy an AWS Lambda function using AWS CodeCommit and AWS CodeBuild. The pipeline works well—all are in the right order, and the build is successful—but it doesn’t create the Lambda according to my code; an error appears during the deploy phase. And also, when creating a new Lambda function, the requirements.txt should contain Python requirements, so those requirements need to be installed as well.
buildspec.yml
:
version: 0.2
env:
variables:
S3_BUCKET: deployment
phases:
install:
runtime-versions:
python: 3.11
commands:
- pip install aws-sam-cli
build:
commands:
- sam build
post_build:
commands:
- sam package --s3-bucket $S3_BUCKET --output-template-file packaged.yaml
artifacts:
files:
- packaged.yaml
template.yml :
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyLambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: lambda_handler.lambda_handler
Runtime: python3.11
CodeUri: s3://deployment/packaged.yaml
MemorySize: 1024
Timeout: 100
Environment:
Variables:
PARAM1: "value1"
Policies:
- AWSLambdaBasicExecutionRole
Error :