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
posta 3 mesi fa196 visualizzazioni
1 Risposta
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
TECNICO DI SUPPORTO
con risposta 3 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande