Serverless- Using AWS CodeStar
Quickly develop, build, and deploy applications on AWS
AWS CodeStar can be used to create, manage and work with software development projects. It helps in developing, building, and deploying applications on AWS with an AWS CodeStar Project.
It brings togethers following AWS services-
AWS CodeCommit (Managed Git Source Code Repository)
AWS CodeBuild (Managed Build Service to build & test code)
AWS CodeDeploy (Automated Software Development)
AWS CloudFormation (Configuration Based Resource Creation)
AWS CodePipeline (Managed CI/CD Pipeline)
Que 1-What is AWS CodeStar used for?
Ans- AWS CodeStar is a cloud-based service for creating, managing, and working with software development projects on AWS. You can quickly develop, build, and deploy applications on AWS with an AWS CodeStar project. It creates and integrates with AWS services, for the project development toolchain. A toolchain might include different types of resources of type source control, build, deploy in serverless or virtual servers environment.
Que 2- Is AWS CodeStar an IDE?
Ans- After you create a project in AWS CodeStar, you can begin developing your code directly in AWS Cloud9, which makes it easy to get started developing on AWS. Cloud9 is a cloud-based IDE that lets you write, run, and debug your code with just a browser.
Que 3- Why should one use AWS CodeStar?
Ans- If you want to quickly set up a software development project on AWS, whether you’re starting with a full set of tools for a team-based project or only setting up a trial project with a source repository, you can go for AWS CodeStar.
AWS CodeStar can also be used by people trying to experiment with CICD and DevOps by starting with a full tool chain for a sample project. AWS CodeStar guides you through the setup experience with project templates that set up real applications and be modified at any point in the future to suit your needs. Plus, CodeStar is completely free of cost. You only pay for resources created for developing and running your applications.
Que 4- What types of applications can I build with AWS CodeStar?
Ans- CodeStar can be used for building web applications, web services and more. The applications run on Amazon EC2, AWS Elastic Beanstalk or AWS Lambda. Project templates are available in several different programming languages including Java, Node.js (Javascript), PHP, Python and Ruby.
Que 5- What are the steps to get started with building a project on AWS CodeStar?
Ans- Getting started with AWS CodeStar can be done in a few minutes through the AWS CodeStar console.
1) Select one of the available CodeStar project templates, which will automatically provision all of the resources needed for your project. Once your project has been provisioned, you can see your running application from the “Application endpoints” tile.
2) Use the steps in the CodeStar console to connect to the AWS CodeCommit source repository for your project and begin coding. You can use the project dashboard to track and manage changes in the release process and see the most recent project activity.
Que 6- What are there third party integrations that I can use with AWS CodeStar?
Ans- AWS CodeStar works with Atlassian JIRA (issue tracking software) to integrate issue management with your projects; In addition, you can add partner actions to your project’s AWS CodePipeline. To see a list of the available CodePipeline actions, refer to the AWS CodePipeline integrations page.
Implement
Create a sample Serverless Python application using CodeStar Project
This lab walks you through how to create an AWS CodeStar project. You will set up a Cloud9 environment to make changes in the application and then test the application.
Architecture Diagram
Task Details:
- Sign in to AWS Management Console. Create an IAM Role for AWS CodeStar
- Create a Project in AWS CodeStar (MyProject)
- Explore project resources created by CodeStar
- Setup AWS Cloud9 workstation to edit project code
- Add logic to the web service
- Wait until the changes are done in the pipeline.
- Test the application and check the Logs
Solution:
Task 1 👉: Sign in to AWS Management Console, Create an IAM Role for AWS CodeStar
- Signed In to the AWS Management Console, Make the default AWS Region as US East (N. Virginia) us-east-1.
- Navigate to CodeStar by clicking on the Services menu at the top, under the Developer Tools section.
- Navigate to Projects from the left panel and click on the Create service role button.
Note: If you don’t see this option, it means the role is already present, skip this part and proceed with the next task. Role with the name aws-codestar-service-role will be created immediately.
Task 2 👉: Create a Project in AWS CodeStar
- To create a Project, click on the Create project button.
- Choose a project template, click on the Search bar present and Select AWS Lambda as AWS Service, Web service as the Application Type, and Python in the Programming language.
Select the project and click on the Next button.
3. Set up your project:
Project name: Enter MyProject
Keep all the options as default and click on the Next button.
Review everything and click on the Create project button.
The project is getting provisioned and it can take up to 10 minutes.
Alternatively, you can check the resources getting created by CodeStar in the CloudFormation console.
- Navigate to CloudFormation by clicking on the Services menu at the top, under the Management & Governance section.
- Stack named awscodestar-myproject is getting created. Click on the Stack name to check out the resources and events.
- Switch to Events, Resources then Parameters tab to know more.
- Upon successful creation of stack named awscodestar-myproject, another stack will be created called as awscodestar-myproject-infrastructure
- Check out their Events, Resources, and Parameters section too.
Only upon successful creation of the second stack with CREATE-COMPLETE status proceed with the next task.
Task 3 👉: Explore project resources created by CodeStar
- Make sure you are in US East (N. Virginia) us-east-1 Region. Navigate to CodeStar by clicking on the Services menu at the top, under the Developer Tools section.
- Navigate to Projects from the left panel and there you will see the created project. Click on the project name.
- On the project details page, click on the View application button. You will be able to see the output and timestamp in JSON format.
Now go back to the project and in the Overview tab, you will be able to see Project resources below.
- Project resources listing:
- 1 Lambda function: It contains the logic of the web service.
- 4 IAM Role, and 1 IAM Policy
- 1 CodePipeline pipeline
- 1 CodeDeploy application and CodeDeploy deployment group
- 1 CodeCommit repository
- 1 CodeBuild Project
- 2 CloudFormation stack
- 1 Amazon S3 bucket
- 1 API in API Gateway
Task 4 👉: Setup Cloud9 workstation to edit project code
- Scroll up and click on the Set up AWS Cloud9 button.
- On the Create AWS Cloud9 Environment details page,
Instance type: Select t2.micro
VPC: Select default VPC
Subnet: Select any subnet
Environment name: Enter demo
Environment description: Cloud9 environment for editing project code
Cost-saving settings: Select After 1 hour
Click on the Create environment button.
It may take up to 5 minutes for creating the Cloud9 environment, you can check the same in the CloudFormation console.
Get Sumbul Naqvi’s stories in your inbox
Join Medium for free to get updates from this writer.
In the mean time, let’s check in the CloudFormation console.
- Navigate to CloudFormation by clicking on the Services menu at the top, under the Management & Governance section.
- Stack named aws-cloud9-demo-RANDOM_ID is getting created. Click on the Stack name to check out the resources and events.
After 5 minutes, you can see the status as CREATE_COMPLETE.
Go back to the codestar console, switch to the IDE tab, and refresh the page. Upon refreshing, you can see a demo environment is present, click on the Open IDE button.
- Cloud9 will prepare the environment for you, within few moments, you can see the CodeCommit repository getting cloned.
- If your Cloud9 page is the same as shown in the below screenshot, you are ready for the next task.
Task 5 👉: Add logic to the web service
- On the CloudShel CLI, you will perform all the commands.
- Head inside the project folder, by listing the files first and then change the directory, run the below commands.
clear
ls
cd myproject
lsCreate a file named hello.py using : vi hello.py
vi hello.pyPaste the below code in the file, to do that perform the following command:
import json
def handler(event, context):
data = {
'output': 'Hello ' + event["pathParameters"]["name"]
}
return {
'statusCode': 200,
'body': json.dumps(data),
'headers': {'Content-Type': 'application/json'}
}Note: Press i to switch to insert mode. Copy and paste the above code in the CloudShell CLI. Once the code is pasted, press esc and :wq to save and close the file.
List all the files once again and make sure hello.py is present.
lsNote: The preceding code outputs the string Hello and the string the caller sends to the function.
- Now you will modify the template.yml file
- To modify perform the following tasks:
- First, copy the file from the S3 bucket and do that first list the bucket and copy the bucket name.
aws s3 ls- Copy the bucket name starting with whizlabs followed by random numbers.
- Once the bucket name is copied, run the below command and replace the bucket name
- aws s3 cp s3://<bucket-name> . — recursive
Note: Don’t forget to put a dot (.) at the end of the command. You are using — recursive to copy all the objects in one go.
- Once the files are copied, check them once and push them back to the CodeCommit repository.
- To push the files, first, we need to add(stage), commit, then push. Run the below commands on the CloudShell CLI.
aws s3 ls
git add .
git commit -m "created and updated files"
git pushTask 6 👉: Wait until the changes are done in the pipeline
- Make sure you are in the US East (N. Virginia) us-east-1 Region.
- Navigate to CodeStar by clicking on the Services menu at the top, under the Developer Tools section.
- Navigate to Projects from the left panel, and click on the project present. Switch to the pipeline tab and wait until all the stages show the status as succeeded.
As soon as run the git push command, changes are added to the CodeCommit repository, and the CodePipeline pipeline detects and changes and takes immediate action.
The source stage is where your code is getting updated.
In the build stage, the application’s required files are getting collected and the application is getting build.
For the Deploy stage, it will take up to 10 minutes, because the changes are getting deployed on the CodeStar application.
Task 7 👉: Test the application and check the logs
- Make sure you are in the US East (N. Virginia) us-east-1 Region. Navigate to CodeStar by clicking on the Services menu at the top, under the Developer Tools section.
- Navigate to Projects from the left panel, and click on the project present. Click on the View application to check the output.
The output is the same, now add /hello/<your_name> at the end of the application URL. You can see your name is getting shown in the output.
To check the application build logs, click on the AWS CodeBuild link under the build stage.
Under the build history, click on the build run of the latest build i.e. 2.
Logs will be loaded and may take some time, scroll below and check the output.
Do You Know?
AWS has repositories on GitHub for these templates. For instance, if you’re looking to start with a Python-based Lambda function using AWS SAM (Serverless Application Model), you don’t necessarily need to begin the project from the AWS CodeStar console.
Conclusion
You have successfully created an IAM role for the CodeStar project.
You have successfully created an AWS CodeStar project.
You have successfully viewed the application explored the resources created by the CodeStar project.
You have successfully done the setup of the Cloud9 environment.
You have successfully modified and updated the code files for adding the web logic to the application.
You have successfully tested the application and checked the output.
Thanks.
Happy learning & sharing😊
Sumbul







