AWS Lambda Serverless Deployment: Next Steps for AWS Certified Developer Exam

Next Steps for Serverless Deployment

Prev Question Next Question

Question

Your team is looking into the Serverless deployment of an AWS lambda function.

The function will be deployed using the Serverless application model.

To test this out, you first create a sample function created below. var AWS = require('aws-sdk'); exports.handler = function(event, context, callback) { var bucketName = "Demobucket"; callback(null, bucketName); } What should be the next steps in the serverless deployment? Choose 2 answers from the options given below.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - A and D.

This is given in the AWS Documentation.

Option B is incorrect since you need to package both the application function and the YAML file.

Option C is incorrect since you have the requirement to deploy this in an automated fashion.

Please refer to the below link, Step 3 and Step 4, for further details.

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-quick-start.html
Step 3: Package the Application

‘After testing your application locally, you use the AWS SAM CL to create a deployment package. You use this package to deploy the application
to the AWS Cloud

Note

In the following steps, you create a zip file for the contents of the hello_word/ directory, which contains the application code. This,

zip file is the deployment package for your serverless application. For more information, see Creating a Deployment Package
(Python) in the AWS Lambda Developer Guide.

To create a Lambda deployment package

1. Create an S3 bucket in the location where you want to save the packaged code. If you want to use an existing $3 bucket, skip this step.

2. Create the Lambda function deployment package by running the following package AWS SAM CLI command at the command prompt.

The command does the following:

+ Zips the contents of the sam-app/hello_world/ directory and uploads it to Amazon S3.

+ Outputs a new template file, called packaged.yaml, which you use in the next step to deploy the application to the AWS Cloud. The
packaged. yaml template file is similar to the original template file (template .yaml), but has one key difference—the CodeUri
property points to the Amazon S3 bucket and object that contains the Lambda function code and dependencies. The following
snippet from an example packaged. yaml template file shows this property:

To deploy a serverless AWS Lambda function using the Serverless Application Model (SAM), you need to follow the following steps:

  1. Write the function code: The first step is to write the code for your Lambda function. In this case, a sample function is given in the question, which can be used to test the deployment process.

  2. Create a SAM Template: Create a YAML file that defines the AWS resources that make up your serverless application, including the function, event sources, permissions, and any other resources you need. The SAM Template is the deployment specification that is used to deploy your serverless application.

  3. Package the code and dependencies: Use the SAM CLI to package your Lambda function code and any dependencies into an Amazon S3 bucket. The package command will create a ZIP file of your code and dependencies and upload it to the S3 bucket you specify. The packaged code will be used by AWS Lambda to create a new version of your function.

  4. Deploy the SAM Template: Use the SAM CLI to deploy your serverless application. This command creates and configures the AWS resources defined in the SAM Template. The deploy command will create or update the CloudFormation stack that represents your serverless application.

  5. Test the function: Use the AWS Lambda console or the AWS CLI to test your Lambda function. You can pass in test events to see how your function responds.

Based on the above steps, the correct answers to the question are A and D.

A. Create a YAML file with the deployment specific's and package that along with the function file: This step is required to create the SAM Template, which defines the AWS resources that make up your serverless application, including the function, event sources, permissions, and any other resources you need. The packaged code and the YAML file are required to deploy the serverless application.

D. Upload the complete package onto an S3 bucket: This step is required to package the code and dependencies using the SAM CLI and upload the ZIP file to an S3 bucket. The packaged code will be used by AWS Lambda to create a new version of your function.