Manual Instructions - PaulDuvall/cloudproviders GitHub Wiki

Manual Instructions

DynamoDB

Create a new DynamoDB table named CloudProviders by running this command:

aws dynamodb create-table --table-name CloudProviders --attribute-definitions AttributeName=ServiceName,AttributeType=S AttributeName=id,AttributeType=N --key-schema AttributeName=ServiceName,KeyType=HASH AttributeName=id,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Insert data into the DynamoDB CloudProviders table by running this command:

aws dynamodb batch-write-item --request-items file://manual/put-items.json
  1. Go to the DynamoDB Tables Console and click on the CloudProviders table and click on the Items pane to view the data.

IAM

  1. Create a new IAM Policy using iam-lambda-dynamodb.json for Lambda. Name it lambda-cloudproviders-cwlogs-policy.
  2. Create a new IAM Role using Lambda as the service. Attach the lambda-cloudproviders-cwlogs-policy policy. Name the role lambda-dynamodb-cloudproviders-role.
  3. Create an Inline Policy for the role using iam-dynamodb-write-policy.json. Replace the ACCOUNTID with the output of aws sts get-caller-identity --output text --query 'Account'. Name it lambda-dynamodb-cloudproviders-inline.

Lambda Read Function

  1. Create a new Lambda Function. Name the Lambda Function CloudProvidersRead. Use the Nodejs 12.x Runtime. Assign the lambda-dynamodb-cloudproviders-role IAM Role.
  2. Click the Create function button.
  3. Replace the contents of index.js in the Function code area with the contents of index.js.
  4. Click the Save button.
  5. Click on the Test button and name the event test and enter {} and click the Create button.
  6. Click on the Test button.

API Gateway (REST API - Recommended)

  1. Go to API Gateway Console.
  2. Click on APIs.
  3. Click the Create API button.
  4. In the REST API section, click on the Build button.
  5. In the Choose the protocol section, choose the REST radio button.
  6. In the Create new API section, choose the New API radio button.
  7. In the API name* section, enter CloudProviders.
  8. Click the Create API button.
  9. Under Actions, select Create Resource.
  10. Enter clouds in the Resource Name* section.
  11. Select the Enable API Gateway CORS checkbox.
  12. Click Create Resource button.
  13. From Actions, select the *Create Method menu option.
  14. Select GET
  15. Choose Lambda Function for the Integration type.
  16. Enter CloudProvidersRead ARN for the Lambda Function.
  17. Click Save.
  18. Under Actions, click Deploy API. You will be asked to provide a name for the stage. Name it default.
  19. Click the Deploy button.
  20. On the Review and create* pane, click Create.
  21. Click on the Invoke URL link and add /clouds to the end of the URL to see a list of the data retrieved from DynamoDB through API Gateway and Lambda. For example the URL might look something like this (it's just an example; this link will not work): https://lgfd5hgta9.execute-api.us-east-1.amazonaws.com/default/clouds

API Gateway (HTTP API - Not Currently Recommended)

  1. Go to API Gateway Console.
  2. Click on APIs.
  3. Click the Create API button.
  4. In the HTTP API section, click on the Build button.
  5. Click on Add integration.
  6. Select Lambda.
  7. Choose the CloudProvidersRead Lambda function.
  8. Enter CloudProviders for the API name.
  9. Click Next.
  10. Enter /clouds for the Resource path.
  11. Enter GET for the Method.
  12. Click Next.
  13. In the Configure stages pane, enter default for the Stage name.
  14. Click Next.
  15. On the Review and create* pane, click Create.
  16. Click on the Invoke URL link and add /clouds to the end of the URL to see a list of the data retrieved from DynamoDB through API Gateway and Lambda. For example the URL might look something like this (it's just an example; this link will not work): https://lgfd5hgta9.execute-api.us-east-1.amazonaws.com/default/clouds

Lambda Post Function

  1. Create a new Lambda Function. Name the Lambda Function CloudProvidersWrite. Use the Nodejs 12.x Runtime. Assign the lambda-dynamodb-cloudproviders-role IAM Role.
  2. Click the Create function button.
  3. Replace the contents of index.js in the Function code area with the contents of index.js.
  4. Click the Save button.
  5. Click on the Test button and enter test as the Event name and copy the contents from write-test.json and click the Create button.
  6. Click on the Test button.
  7. Go to the DynamoDB Tables Console and click on the CloudProviders table and click on the Items pane to verify a new item has been added to the DynamoDB table.

Integrate Lambda Function with API Gateway (REST API - Recommended)

  1. Go to API Gateway Console.
  2. Click on APIs.
  3. Select CloudProviders.
  4. Select the /clouds resource.
  5. Under Actions, select Create Method.
  6. Enter POST and confirm.
  7. Enter CloudProvidersWrite for the Lambda function and click Save.
  8. With the POST method selected, click on Integration Request.
  9. Scroll down and select the Mapping Templates section.
  10. Choose the When there are no templates defined (recommended) radio button.
  11. Click on Add mapping template.
  12. Enter application/json for the Content-Type and click the confirm checkmark.
  13. Copy the contents from mapping-template.json into the text body and click Save.
  14. Under Actions click Deploy API. You will be asked to provide a name for the stage. Select the default stage and Deploy. In the Stages pane there is an Invoke URL.

Integrate Lambda Function with API Gateway (HTTP API - Not Currently Recommended)

  1. Go to API Gateway Console.
  2. Click on APIs.
  3. Select CloudProviders.
  4. Click on Routes.
  5. Click Create.
  6. On the Create a route pane, select POST from the method dropdown and enter /post for the route.
  7. Click Create.
  8. Click on the POST route and click the Attach integration button.
  9. Click the Create and attach an integration button.
  10. On the Review and create* pane, click Create.
  11. Select Lambda Function radio button in the Integration with section.
  12. Choose the CloudProvidersWrite for the Lambda function in the Integration details section.
  13. Click the Create button.
  14. Click on the Invoke URL link and add /clouds to the end of the URL to see a list of the data retrieved from DynamoDB through API Gateway and Lambda. For example the URL might look something like this (it's just an example; this link will not work): https://lgfd5hgta9.execute-api.us-east-1.amazonaws.com/default/clouds

Post new data via API

curl -X POST https://APIGATEWAYID.execute-api.us-east-1.amazonaws.com/default/clouds -H 'Content-Type: application/json' -d '{"servicename": "PMD NEW SERVICE", "cloudprovider": "aws", id: 400, "url": "https://aws.amazon.com/pmd/"}'

curl -X POST https://APIGATEWAYID.execute-api.us-east-1.amazonaws.com/default/clouds -H 'Content-Type: application/json' -d '{"servicename": "CodeDeploy", "cloudprovider": "aws", id: 500, "url": "https://aws.amazon.com/codedeploy/"}'

Troubleshooting

aws dynamodb create-table --table-name CloudProviders --attribute-definitions AttributeName=ServiceName,AttributeType=S AttributeName=id,AttributeType=N --key-schema AttributeName=ServiceName,KeyType=HASH AttributeName=id,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

aws dynamodb batch-write-item --request-items file://manual/request-items.json
{
  "servicename": "ABC Service",
  "cloudprovider": "AWS",
  "id": 204,
  "url": "https://aws.amazon.com/abc/"
}
curl -X POST https://ivqyiz8xg6.execute-api.us-east-1.amazonaws.com/default/clouds -H 'Content-Type: application/json' -d '{"servicename": "PMD WED NEW SERVICE", "cloudprovider": "AWS", id: 110, "url": "https://aws.amazon.com/pmd/"}'