Need a help to configure bitbucket repository with AWS beanstalk pipeline

0

I'm trying to configure BitBucket repository with AWS Beanstalk environment to deploy code automatically. Can you suggest me the steps to complete this configuration?

Asela
질문됨 3달 전196회 조회
1개 답변
0

The automatic deployment of code in AWS Elastic Beanstalk using Bitbucket repository can be achieve with the help of AWS CodePipeline. You can refer to this hands-on guide [1], which talks about automatic code deployment in AWS Elastic Beanstalk using AWS CodePipeline. To configure Bitbucket as Source location for your pipeline, you have to create a CodeStar Connection [2]. Once the Connection is created, you can configure your pipeline source with Bitbucket repository. To achieve the same using CDK, you can check the below sample code which is written in typescript language :

Prerequisite : Bitbucket CodeStar connection


import * as elasticbeanstalk from 'aws-cdk-lib/aws-elasticbeanstalk';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import * as codepipeline from 'aws-cdk-lib/aws-codepipeline';
import * as cpactions from 'aws-cdk-lib/aws-codepipeline-actions';

Code for creating AWS Elastic Beanstalk Application and Environment


// code for creating AWS Elastic Beanstalk application and environment

    const ebApp = new elasticbeanstalk.CfnApplication(this, 'ElasticBeanstalkApplication', {
      resourceLifecycleConfig: {
        serviceRole: "<aws-elasticbeanstalk-service-role-Arn>",
        versionLifecycleConfig: {
          maxCountRule: {
            enabled: false,
            deleteSourceFromS3: false,
            maxCount: 200,
          },
          maxAgeRule: {
            maxAgeInDays: 180,
            enabled: false,
            deleteSourceFromS3: false,
          },
        },
      },
      applicationName: 'MyApp',
    });
    
  const ebEnvironment = new elasticbeanstalk.CfnEnvironment(this, 'MyCfnEnvironment', {
    applicationName: ebApp.ref,
    environmentName: 'ebenvironment',
    solutionStackName: "64bit Amazon Linux 2023 v4.0.8 running Python 3.9",
    optionSettings: [{
    namespace: 'aws:autoscaling:launchconfiguration',
    optionName: 'IamInstanceProfile',
    value: '<Instance-profile-ARN>',
  }]
  });

Creating Pipeline Stages


// Configuring bitbucket as source

  const source = new cpactions.CodeStarConnectionsSourceAction({
  actionName: 'BitBucket_Source',
  connectionArn: "<CodeStar Connection ARN>",
  repo: "<repository Name>",
  output: sourceOutput,
  owner: "<Owner>",
  branch: "<branch-name>"
});

// Adding beanstalk as deployment target

const deployAction = new cpactions.ElasticBeanstalkDeployAction({
  actionName: 'ElasticBeanstalkDeploy',
  input: sourceOutput,
  environmentName: "ebenvironment",
  applicationName: "MyApp"
});

Configuring CodePipeline

// Create pipeline
  const pipeline = new codepipeline.Pipeline(this, 'CICD-pipeline',{
    pipelineName: "CICD-pipeline"
  });
  
  pipeline.node.addDependency(ebEnvironment)

  // Adding codepipeline stage

  pipeline.addStage(
    {
      stageName: "Source",
      actions: [source]
    })

pipeline.addStage(
    {
      stageName: "Deploy",
      actions: [deployAction]
    })

References:

[1] https://aws.amazon.com/getting-started/hands-on/continuous-deployment-pipeline/

[2] Create a connection to Bitbucket - https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create-bitbucket.html

AWS
지원 엔지니어
답변함 3달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠