I'm trying to build a pipeline to automate a lambda function deployment on AWS. I created a pipeline, a codebuild and needed IAM roles and integrated them with cloudformation.
here's my buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 14
commands:
- echo "Installing from package.json"
# - npm install
pre_build:
commands:
- echo "Build on `date`"
# - npm run test
post_build:
commands:
- zip -r lambda.zip index.js template.yml
- aws s3api put-object --bucket github-lambda-demo --key lambda.zip --body lambda.zip
artifacts:
files:
- template.yml
discard-paths: yes
And this is my cloudformation template:
AWSTemplateFormatVersion: '2010-09-09'
Description: Template for Lambda Sample.
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: lambda-role
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: github-lambda-demo
S3Key: lambda.zip
Description: demo for lambda deployment
FunctionName: github-lambda-demo
Handler: index.handler
PackageType: Zip
# Layers:
# - String
MemorySize: 256
Role:
Fn::GetAtt:
- LambdaRole
- Arn
Runtime: nodejs14.x
Timeout: 300
All the steps are done quite right with no errors in codePipeline but my lambda function source is not being update as it should be.
Any help?!