- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
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
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 4 Jahren
- AWS OFFICIALAktualisiert vor 9 Monaten
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor 3 Jahren