Change Lambda Resource Name in CodeStar Project | DOP-C01 Exam Prep

Change Lambda Resource Name to "XXX-DemoProject"

Prev Question Next Question

Question

You are just promoted to be the Scrum Master of a new team.

You want to try something new and start using CodeStar because of its wonderful project management features.

You plan to create a sample project using Node.js template which CodeStar provides and demo to other team members.

You create the demo project successfully and the Node.js project is deployed smoothly in Lambda.

The project code is in CodeCommit.

Later on you want to change the lambda resource name from “XXX-GetHelloWorld” to “XXX-DemoProject”

What option should you use?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

Instead of manually modifying an infrastructure resource, use AWS CloudFormation to model and deploy your application's runtime resources.

You can modify or add an application resource, such as a Lambda function, in your runtime stack by editing the template.yml file in your project repository.

You can add any resource that is available as a AWS CloudFormation resource.

For example, you could modify the Lambda resource name in below code:

Details please refer to https://docs.aws.amazon.com/codestar/latest/userguide/templates.html#update-project.

Option A is incorrect: Because buildspec.yml is for CodeBuild instead of CloudFormation.

Lambda belongs to CloudFormation stack so that template.yml is needed.

Option B is incorrect: Because you can still modify the sample code by changing the code in CodeCommit or Github repo.

Option D is incorrect: For CodeStar, although manually changing Lambda resource could work, it is not a good practice.

Managing resources in CloudFormation is suggested so that the structure is regarded as Code and can be properly managed.

Resources:

GetHelloWorld:
Type: AWS: :Serverless: : Function
Properties:
Handler: index.get
Runtime: nodejs8.10
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
LambdaExecutionRole:
Description: Creating service role in IAM for AWS Lambda
Type: AWS: :IAM::Role
Properties:
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'

The correct option in this scenario is Option C.

As the project code is in CodeCommit, the application resource name can be modified in the template.yml file in the CodeCommit repo. The template.yml file is also the AWS CloudFormation file that models the application's runtime environment.

AWS CloudFormation is a service that allows you to model and provision AWS resources in a predictable and repeatable way. It uses templates, which are JSON or YAML formatted text files, to describe the infrastructure and application resources needed to run an application.

To change the lambda resource name, you can modify the template.yml file and update the relevant resource name to "XXX-DemoProject". Once the changes are committed to the CodeCommit repository, CodeStar will pick up the changes and deploy the updated Lambda function.

Option A is not the best choice as it involves making changes to the buildspec.yml file, which is used by CodeBuild to build and package the application. Changing the Lambda resource name does not require changes to the buildspec.yml file.

Option B is incorrect as AWS CodeStar templates are not read-only. While the templates provided by CodeStar are designed to be used as a starting point, they can be modified to suit the specific needs of the project.

Option D is not recommended as it involves manually changing the resource name in the Lambda console. This is not an ideal solution as it can be error-prone and may result in inconsistencies between the template and the actual deployed resources. It also goes against the principles of infrastructure as code, which emphasizes using templates to describe the infrastructure and application resources.