Social Buttons




vendredi 12 juin 2020

Visite out website
AWS Certified Cloud Practitioner
AWS Certified Solutions Architect Associate
AWS Certified Developer Associate
AWS Certified SysOps Administrator Associate
AWS Certified Solutions Architect Professional
AWS Certified DevOps Engineer Professional
AWS Certified Big Data Specialty
AWS Certified Advanced Networking Specialty
AWS Certified Security Specialty
Visite out website
Visite out website
AWS Certified Cloud Practitioner
AWS Certified Solutions Architect Associate
AWS Certified Developer Associate
AWS Certified SysOps Administrator Associate
AWS Certified Solutions Architect Professional
AWS Certified DevOps Engineer Professional
AWS Certified Big Data Specialty
AWS Certified Advanced Networking Specialty
AWS Certified Security Specialty
Visite out website May 29, 2020: Post updated to include AWS CodePipeline support to invoke Step Functions with a new action type.
Automating your software build is an important step to adopt [120]DevOps best practices. To help you with that, we built [121]AWS CodeBuild, a fully managed continuous integration service that compiles source code, runs tests, and produces packages that are ready for deployment, and [122]AWS CodePipeline, a fully managed continuous delivery service to automate your release pipelines.
However, there are so many possible customizations in our customers’ build processes, and we have seen developers spend time in creating their own custom workflows to coordinate the different activities required by their software build. For example, you may want to run, or not, some tests, or skip [123]static analysis of your code when you need to deploy a quick fix. Depending on the results of your unit tests, you may want to take different actions, or be notified via [124]SNS.
CodePipeline is currently optimized for releasing software and infrastructure in production. It includes release safety features that don’t exist in general workflow automation tools. On the other side, CodePipeline isn’t currently optimized for non-release scenarios such as orchestrating validation of a change prior to release, or for running multiple builds in parallel. To simplify those use cases, we are launching today a new [125]AWS Step Functions [126]service integration with CodeBuild. Now, during the execution of a state machine, you can [127]start or [128]stop a build, [129]get build report summaries, and [130]delete past build executions records.
In this way, you can define your own workflow-driven build process, and trigger it manually or automatically. For example you can: * Use the new [131]CodePipeline support to invoke Step Functions to customize your delivery pipeline with choices, external validations, or parallel tasks. Each of those tasks can now call CodeBuild to create a custom build following specific requirements. * Use [132]Amazon EventBridge rules to start the build workflow periodically (for nightly builds) or when something happens (such as a a pull request to an [133]AWS CodeCommit repository). * Build a [134]webhook that can be called by services such as GitHub using the [135]Amazon API Gateway, either with a [136]direct integration to a state machine, or via a [137]AWS Lambda function that checks the validity of the input payload before starting the workflow.
With this integration, you can use the full capabilities of Step Functions to automate your software builds. For example, you can use a [138]Parallel state to create parallel builds for independent components of the build. Starting from a list of all the branches in your code repository, you can use a [139]Map state to run a set of steps (automating build, unit tests, and integration tests) for each branch. You can also leverage in the same workflow other Step Functions [140]service integrations. For instance, you can send a message to an [141]SQS queue to track your activities, or start a containerized application you just built using [142]Amazon ECS and [143]AWS Fargate.
Using Step Functions for a Workflow-Driven Build Process I am working on a Java web application. To be sure that it works as I add new features, I wrote a few tests using [144]JUnit Jupiter. I want those tests to be run just after the build process, but not always because tests can slow down some quick iterations. When I run tests, I want to [145]store and view the reports of my tests using CodeBuild. At the end, I want to be notified in an [146]SNS topic if the tests run, and if they were successful.
I created a repository in [147]CodeCommit and I included two [148]buildspec files for CodeBuild: * buildspec.yml is the default and is using [149]Apache Maven to run the build and the tests, and then is storing test results as reports.
version: 0.2 phases: build: commands: - mvn package artifacts: files: - target/binary-converter-1.0-SNAPSHOT.jar reports: SurefireReports: files: - '**/*' base-directory: 'target/surefire-reports' * buildspec-notests.yml is doing only the build, and no tests are executed.
version: 0.2 phases: build: commands: - mvn package -DskipTests artifacts: files: - target/binary-converter-1.0-SNAPSHOT.jar
To set up the CodeBuild project and the Step Functions state machine to automate the build, I am using [150]AWS CloudFormation with the following template: AWSTemplateFormatVersion: 2010-09-09 Description: AWS Step Functions sample project for getting notified on AWS CodeB uild test report results Resources: CodeBuildStateMachine: Type: AWS::StepFunctions::StateMachine Properties: RoleArn: !GetAtt [ CodeBuildExecutionRole, Arn ] DefinitionString: !Sub - |- { "Comment": "An example of using CodeBuild to run (or not run) test s, get test results and send a notification.", "StartAt": "Run Tests?", "States": { "Run Tests?": { "Type": "Choice", "Choices": [ { "Variable": "$.tests", "BooleanEquals": false, "Next": "Trigger CodeBuild Build Without Tests" } ], "Default": "Trigger CodeBuild Build With Tests" }, "Trigger CodeBuild Build With Tests": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::codebuild:startBui ld.sync", "Parameters": { "ProjectName": "${projectName}" }, "Next": "Get Test Results" }, "Trigger CodeBuild Build Without Tests": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::codebuild:startBui ld.sync", "Parameters": { "ProjectName": "${projectName}", "BuildspecOverride": "buildspec-notests.yml" }, "Next": "Notify No Tests" }, "Get Test Results": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::codebuild:batchGet Reports", "Parameters": { "ReportArns.$": "$.Build.ReportArns" }, "Next": "All Tests Passed?" }, "All Tests Passed?": { "Type": "Choice", "Choices": [ { "Variable": "$.Reports[0].Status", "StringEquals": "SUCCEEDED", "Next": "Notify Success" } ], "Default": "Notify Failure" }, "Notify Success": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::sns:publish", "Parameters": { "Message": "CodeBuild build tests succeeded", "TopicArn": "${snsTopicArn}" }, "End": true }, "Notify Failure": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::sns:publish", "Parameters": { "Message": "CodeBuild build tests failed", "TopicArn": "${snsTopicArn}" }, "End": true }, "Notify No Tests": { "Type": "Task", "Resource": "arn:${AWS::Partition}:states:::sns:publish", "Parameters": { "Message": "CodeBuild build without tests", "TopicArn": "${snsTopicArn}" }, "End": true } } } - {snsTopicArn: !Ref SNSTopic, projectName: !Ref CodeBuildProject} SNSTopic: Type: AWS::SNS::Topic CodeBuildProject: Type: AWS::CodeBuild::Project Properties: ServiceRole: !Ref CodeBuildServiceRole Artifacts: Type: NO_ARTIFACTS Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:2.0 Source: Type: CODECOMMIT Location: -converter CodeBuildExecutionRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: "sts:AssumeRole" Principal: Service: Path: "/" Policies: - PolicyName: CodeBuildExecutionRolePolicy PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - "sns:Publish" Resource: - !Ref SNSTopic - Effect: Allow Action: - "codebuild:StartBuild" - "codebuild:StopBuild" - "codebuild:BatchGetBuilds" - "codebuild:BatchGetReports" Resource: "*" - Effect: Allow Action: - "events:PutTargets" - "events:PutRule" - "events:DescribeRule" Resource: - !Sub "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::Acc ountId}:rule/StepFunctionsGetEventForCodeBuildStartBuildRule" CodeBuildServiceRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: "sts:AssumeRole" Effect: Allow Principal: Service: Path: / Policies: - PolicyName: CodeBuildServiceRolePolicy PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - "logs:CreateLogGroup" - "logs:CreateLogStream" - "logs:PutLogEvents" - "codebuild:CreateReportGroup" - "codebuild:CreateReport" - "codebuild:UpdateReport" - "codebuild:BatchPutTestCases" - "codecommit:GitPull" Resource: "*" Outputs: StateMachineArn: Value: !Ref CodeBuildStateMachine ExecutionInput: Description: Sample input to StartExecution. Value: > {}
When the [151]CloudFormation stack has been created, there are two CodeBuild tasks in the state machine definition: * The first CodeBuild task is using a synchronous integration (startBuild.sync) to automatically wait for the build to terminate before progressing to the next step:
"Trigger CodeBuild Build With Tests": { "Type": "Task", "Resource": "arn:aws:states:::codebuild:startBuild.sync", "Parameters": { "ProjectName": "CodeBuildProject-HaVamwTeX8kM" }, "Next": "Get Test Results" } * The second CodeBuild task is using the BuildspecOverride parameter to override the default buildspec file used by the build with the one not running tests:
"Trigger CodeBuild Build Without Tests": { "Type": "Task", "Resource": "arn:aws:states:::codebuild:startBuild.sync", "Parameters": { "ProjectName": "CodeBuildProject-HaVamwTeX8kM", "BuildspecOverride": "buildspec-notests.yml" }, "Next": "Notify No Tests" },
The first step is a [152]Choice that looks into the input of the state machine execution to decide if to run tests, or not. For example, to run tests I can give in input: { "tests": true }
This is the visual workflow of the execution running tests, all tests are passed.
I change the value of "tests" to false, and start a new execution that goes on a different branch.
This time the buildspec is not executing tests, and I get a notification that no tests were run.
When starting this workflow automatically after an activity on GitHub or [153]CodeCommit, I could look into the last commit message for specific patterns, and customize the build process accordingly. For example, I could skip tests if the [skip tests] string is part of the commit message. Similarly, in a production environment I could skip code static analysis, to have faster integration for urgent changes, if the [skip static analysis] message in included in the commit.
Extending the Workflow for Containerized Applications A great way to distribute applications to different environments, is to package them as [154]Docker images. In this way, I can also add a step to my build workflow and start the containerized application in an [155]Amazon ECS task (running on [156]AWS Fargate) for the Quality Assurance (QA) team.
First, I create an image repository in ECR and add permissions to the service role used by the CodeBuild project to upload to ECR, as [157]described here.
Then, in the code repository, [158]I follow this example to add: * A Dockerfile to prepare the Docker container with the software build, and start the application. * A buildspec-docker.yml file with the commands to create and upload the Docker image.
The final workflow is automating all these steps: 1. Building the software from the source code. 2. Creating the Docker image. 3. Uploading of the Docker image to ECR. 4. Starting the QA environment on ECS and [159]Fargate. 5. Sending an [160]SNS notification that the QA environment is ready.
The workflow and its steps can easily be customized based on your requirements. For example, with a few changes, you can [162]adapt the buildspec file to push the image to Docker Hub.
Available Now The CodeBuild service integration is available in all commercial and GovCloud regions where Step Functions and CodeBuild services are offered. For regional availability, please see the [163]AWS Region Table. For more information, [164]please look at the documentation.
As [165]AWS Serverless Hero Gojko Adzic pointed out on the [166]AWS DevOps Blog, [167]CodeBuild can also be used to execute administrative tasks. The integration with Step Functions opens a whole set of new possibilities.
Let me know what are you going to use this new service integration for!
â€" [168]Danilo
Danilo Poccia
[169]Danilo Poccia
Danilo works with startups and companies of any size to support their innovation. In his role as Chief Evangelist (EMEA) at Amazon Web Services, he leverages his experience to help people bring their ideas to life, focusing on serverless architectures and event-driven programming, and on the technical and business impact of machine learning and edge computing. He is the author of AWS Lambda in Action from Manning. [170]View Comments
[171]Getting Started [172]What's New [173]Top Posts [174]Official AWS Podcast [175]Case Studies __________________________________________________________________
[176] Twitter [177] Facebook [178] LinkedIn [179] Twitch [180] RSS Feed [181] Email Updates
[182]Sign In to the Console
Learn About AWS
* [183]What Is AWS? * [184]What Is Cloud Computing? * [185]What Is DevOps? * [186]What Is a Container? * [187]What Is a Data Lake? * [188]AWS Cloud Security * [189]What's New * [190]Blogs * [191]Press Releases
Resources for AWS
  • amazon web services consulting
  • aws cloudtrail
  • aws log viewer
  • aws certified solutions architect
  • amazon job search
  • aws firewall logs
  • aws cloudtrail faq
  • aws cloudwatch vs cloudtrail
  • aws cloudtrail documentation
  • aws solutions architect certification


    Aucun commentaire:

    Publier un commentaire

    Nombre total de pages vues