Uncategorized

Deploy Python Lambda with TypeScript CDK


I am new to aws-cdk, trying to deploy a lambda for the first time. I created 2 git repo to keep infra and python scripts separately. 1 Python git repo to store all python scripts required for lambda. 1 typescript git repo to deploy infra using cdk. In my cdk app, I added a prebuild step which will check basic linting, pytest test cases. once deployed, i can see my entire python repo is zipped and present in s3 bucket created by cdk at location ‘artifactBucket/MyPipeLineName/bharath-t/ONvvlDC.zip’. PipelineStage internally deploys a lambda stack. How can i access python repo s3 zip location within the stack and pass it to pipelinestage which inturn will be used by lambdastack?

import { Stack, StackProps, aws_lambda } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';
import { PipelineStage } from './PipelineStage';
import path = require('path');


export class AwsCdkLearnStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const source = CodePipelineSource.gitHub('bharath-t/aws-cdk-learn', 'main');
    const python_source = CodePipelineSource.gitHub('bharath-t/python-learn', 'main');

    const prebuild = new ShellStep('Prebuild', {
      input: python_source,
      primaryOutputDirectory: './src',
      commands: ['pip install flake8 pytest build', 'flake8 --exit-zero', 'pytest'],
    });

    const pipeline = new CodePipeline(this, 'TestPipeline', {
      pipelineName: 'TestPipeline',
      synth: new ShellStep('Synth', {
        input: source,
        additionalInputs: {
          '../siblingdir': prebuild,
        },
        commands: ['npm ci', 'npx cdk synth'],
      })
    });

    const betaStage = new PipelineStage(this, 'BetaStage', {
      stageName: 'beta',
    });


    pipeline.addStage(betaStage);

  }
}



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *