Amazon Web Services Kickstart Part 2. Rise of the LambdaCreated: 27 April 2022 Modified:
We are looking to get started with Amazon Web Services (AWS). Being complete newbies finding a place to start can be daunting. Never fear you can get started in a few easy steps. We will be setting up an Amazon Web Services (AWS) and installing some command line tools. In some instance corporate intranets or Viratual Private Networks (VPN) may interfere with some functionality of the command line tools. Be aware that there are also plugins for Eclipse and Intellij. At the time of this writing the Eclipse plugins appear somewhat neglected. The last update was several months ago and some irritating bugs are more than two years old. This blog assumes you are running Windows 10.
- Start Command prompt or Power Shell
- Run sam init
- Build and test Hello World project
- Setup lambda execution role.
- Configure lambda
- Upload directly and test
So I run Powershell and change to the directory where I want to store my source code. I then run the “sam init” command.
sam init results
This Lambda code that is now generated will Display a Hello World message wrapped in JSON. Additionally it will reach out to an Amazon Web Service called Checkip and retrieve the IP address of where the code is running. Now we will change to the HelloWorldProject\HelloWorldFunction directory and run “mvn clean package”. You should see something similar to the results below. It is possible that a firewall or corporate VPN will block your access to https://checkip.amazonaws.com. If access to the URL is blocked the unit test will fail.
mvn clean package
Now we will need to make a Lambda execution role. In the AWS cloud identities, roles and policies control what can and cannot be done. In this case we are going to make a role that has an associated policy that will allow a Lambda to execute in the clound. We will name our role lambda-execution-role. Our next step is to manually configure and upload our lambda to AWS. This will help us understand the more automated way we will see later.
- First we will login to AWS Console and navigate to Services -> Compute -> Lambda
- Next we will click the orange Create Function button in the upper right of the page.
- As shown in the screen capture we will name our function HelloWorldFunction.
- In the Runtime section select Java 8.
- Now we will assign the lambda-execution-role we setup earlier.
- In the Permissions section click Change default execution role.
- Select Use and Existing Role
- In the dropdown that appears choose lambda-execution-role.
- Click the orange Create Function button in the lower right of the browser.
- Once the function is created you should see a page similar to the following.
- Select the Code tab. (This should be the default).
- Click the Upload From button and select zip or jar file.
- A dialog will appear and click the Upload button.
- Select the HelloWorld-1.0.jar file found in your projects target directory.
- Click the Save button.
- Scroll down to the Runtime settings section and click the Edit button.
- In the Handler text field enter helloworld.App::handleRequest.
- This matches the package, class name and method in your HelloWorldFunction lambda.
- Click the Save button.
- Select the Test tab and click the orange Test button.
- You should see a green successful result.
We have successfully configured, uploaded and tested an AWS lambda.tags: aws - amazon web services - start - kickstart - lambda - s3 - identity acesss management - iam