CodeCommit e CodeBuild
Integre o AWS CodeCommit para controle de código-fonte e o AWS CodeBuild para compilar e empacotar seu código sem servidor.
CodeCommit e CodeBuild é uma aula grátis de Serverless Backend with AWS Lambda & API Gateway no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Serverless Backend with AWS Lambda & API Gateway, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Serverless Backend with AWS Lambda & API Gateway inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
CI/CD for Serverless Intro
Welcome to the first lesson in our CI/CD for Serverless Applications course! Continuous Integration and Continuous Delivery (CI/CD) are crucial for modern software development.
In this lesson, we'll dive into two foundational AWS services: AWS CodeCommit for source control and AWS CodeBuild for compiling and packaging your serverless code.
What is AWS CodeCommit?
AWS CodeCommit is a fully managed source control service that hosts secure Git-based repositories. Think of it as AWS's version of GitHub or GitLab, but tightly integrated with other AWS services.
- It's private: Your code stays within AWS.
- It's scalable: Handles projects of any size.
- It's Git-compatible: Use your existing Git tools and workflows.
It acts as the central hub for your application's source code.
Setting Up CodeCommit Repo
To start using CodeCommit, you first need to create a repository. You can do this via the AWS Management Console, AWS CLI, or SDKs.
Once created, you'll configure your local Git client to connect to it. This often involves setting up IAM credentials (HTTPS Git credentials) or SSH keys for authentication.
Cloning & Pushing Code
After setting up your credentials, you can clone your CodeCommit repository to your local machine and push changes just like any other Git repository.
Here's a basic sequence of commands you'd use:
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyServerlessRepo
cd MyServerlessRepo
echo "print('Hello CI/CD!')" > app.py
git add app.py
git commit -m "Initial commit for Lambda function"
git push origin mainWhat is AWS CodeBuild?
AWS CodeBuild is a fully managed continuous integration service that compiles your source code, runs tests, and produces deployable software packages. It eliminates the need to provision, manage, and scale your own build servers.
- No servers to manage: AWS handles the infrastructure.
- Scales automatically: Builds run in parallel and scale as needed.
- Pay-as-you-go: You only pay for the compute time used.
The Buildspec File
The core of a CodeBuild project is the buildspec.yml file. This YAML file defines the commands and actions CodeBuild performs during a build.
It specifies build commands, artifact (output) definitions, and caching instructions. It's placed at the root of your source repository.
Anatomy of a Buildspec
A buildspec.yml is organized into phases:
- install: Install dependencies.
- pre_build: Commands before build (e.g., login to Docker).
- build: Actual build commands (e.g., compile code, run tests).
- post_build: Commands after build (e.g., package artifacts).
Here's a simple example for a Python Lambda function:
version: 0.2
phases:
install:
commands:
- echo "Installing dependencies..."
- pip install --upgrade pip
- pip install -r requirements.txt -t package/
build:
commands:
- echo "Zipping deployment package..."
- cd package
- zip -r ../function.zip .
- cd ..
- zip -g function.zip app.py
artifacts:
files:
- function.zip
discard-paths: yesCreating a CodeBuild Project
To use CodeBuild, you create a build project. This involves:
- Source: Pointing to your source code repository (e.g., CodeCommit).
- Environment: Selecting an operating system, runtime, and compute type.
- Buildspec: Specifying the
buildspec.ymlfile. - Artifacts: Defining where to store build outputs (e.g., S3 bucket).
You'll also assign an IAM role to CodeBuild, granting it permissions to access your source, S3, and other necessary AWS services.
CodeCommit & CodeBuild Flow
The typical workflow for continuous integration using these services is:
- Developer pushes code changes to an AWS CodeCommit repository.
- CodeCommit can trigger an AWS CodeBuild project automatically (often via CodePipeline, which we'll cover next).
- CodeBuild fetches the latest code, executes the commands in
buildspec.yml. - CodeBuild produces artifacts (like a zipped Lambda function) and stores them in an S3 bucket, ready for deployment.
Quick Check
You've just learned about CodeCommit and CodeBuild. Let's test your understanding!
Recap & Next Steps
Great job! In this lesson, you learned about:
- AWS CodeCommit: A managed Git repository service for secure source control.
- AWS CodeBuild: A fully managed continuous integration service that compiles and packages your code.
- The importance of the
buildspec.ymlfile for defining build steps.
These two services form the backbone of your serverless CI/CD pipeline. Next, we'll see how AWS CodePipeline orchestrates these services for automated deployments!
Perguntas Frequentes
A aula “CodeCommit e CodeBuild” é grátis?
Sim — o texto completo de “CodeCommit e CodeBuild” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Serverless Backend with AWS Lambda & API Gateway, atualize para CoddyKit PRO. O curso de Serverless Backend with AWS Lambda & API Gateway inclui 4 aulas no total.
O que vou aprender em “CodeCommit e CodeBuild”?
Integre o AWS CodeCommit para controle de código-fonte e o AWS CodeBuild para compilar e empacotar seu código sem servidor. Você pratica Serverless Backend with AWS Lambda & API Gateway com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Serverless Backend with AWS Lambda & API Gateway?
Nenhuma experiência prévia é necessária. Serverless Backend with AWS Lambda & API Gateway no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “CodeCommit e CodeBuild”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Serverless Backend with AWS Lambda & API Gateway?
Sim. Cada aula de Serverless Backend with AWS Lambda & API Gateway inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- CodeCommit e CodeBuild
- CodePipeline para implantações
- Automação de implantações sem servidor
- Implantações seguras com canário e reversão