Lambda Function code to fetch from git

0

I have created a codepipline using the following git link https://github.com/aws-samples/aws-serverless-samfarm/blob/master/pipeline/pipeline.yaml

The Pipeline has been created and I have connected the source to my Git repo(V2). I am using the following file as a SAM Input for lambda creation. How can I make the lambda function fetch the function code stored in a git folder in the same branch where I want to deploy the pipeline? Do I need to create a build spec file or something?

AWSTemplateFormatVersion: '2010-09-09' Description: Lambda function and EventBridge rule for EC2 Instance State Change

Resources: LambdaFunction: Type: AWS::Lambda::Function Properties: FunctionName: xxxxx_xxxx Handler: main.lambda_handler Role: arn:aws:iam::xxxxx:role/xxxxxxxxxx Runtime: python3.8 Timeout: 60

EventBridgeRule: Type: AWS::Events::Rule Properties: Name: sk-poc-usstg-ec2-state-change EventPattern: source: - aws.ec2 detail-type: - EC2 Instance State-change Notification detail: state: - stopped - stopping Targets: - Arn: !GetAtt LambdaFunction.Arn Id: TargetLambda

Outputs: LambdaFunctionArn: Description: ARN of the Lambda function Value: !GetAtt LambdaFunction.Arn

EventBridgeRuleArn: Description: ARN of the Amazon EventBridge rule Value: !Ref EventBridgeRule # Reference the EventBridge rule's ARN

1 Answer
0

Try the following in your buildspec:

  1. cd into the top of your repo copy.
  2. git fetch.
  3. git checkout HEAD path/to/file.
  4. Push code into your lambda.
AWS
vtjean
answered 9 months ago
profile picture
EXPERT
reviewed 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions