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
- Go to the DynamoDB Tables Console and click on the CloudProviders table and click on the Items pane to view the data.
IAM
- Create a new IAM Policy using iam-lambda-dynamodb.json for Lambda. Name it
lambda-cloudproviders-cwlogs-policy
. - Create a new IAM Role using Lambda as the service. Attach the lambda-cloudproviders-cwlogs-policy policy. Name the role
lambda-dynamodb-cloudproviders-role
. - Create an Inline Policy for the role using iam-dynamodb-write-policy.json. Replace the
ACCOUNTID
with the output ofaws sts get-caller-identity --output text --query 'Account'
. Name itlambda-dynamodb-cloudproviders-inline
.
Lambda Read Function
- Create a new Lambda Function. Name the Lambda Function
CloudProvidersRead
. Use theNodejs 12.x
Runtime. Assign thelambda-dynamodb-cloudproviders-role
IAM Role. - Click the Create function button.
- Replace the contents of
index.js
in the Function code area with the contents of index.js. - Click the Save button.
- Click on the Test button and name the event
test
and enter{}
and click the Create button. - Click on the Test button.
API Gateway (REST API - Recommended)
- Go to API Gateway Console.
- Click on APIs.
- Click the Create API button.
- In the REST API section, click on the Build button.
- In the Choose the protocol section, choose the REST radio button.
- In the Create new API section, choose the New API radio button.
- In the API name* section, enter
CloudProviders
. - Click the Create API button.
- Under Actions, select Create Resource.
- Enter
clouds
in the Resource Name* section. - Select the Enable API Gateway CORS checkbox.
- Click Create Resource button.
- From Actions, select the *Create Method menu option.
- Select GET
- Choose
Lambda Function
for the Integration type. - Enter
CloudProvidersRead
ARN for the Lambda Function. - Click Save.
- Under Actions, click Deploy API. You will be asked to provide a name for the stage. Name it
default
. - Click the Deploy button.
- On the Review and create* pane, click Create.
- 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)
- Go to API Gateway Console.
- Click on APIs.
- Click the Create API button.
- In the HTTP API section, click on the Build button.
- Click on Add integration.
- Select Lambda.
- Choose the CloudProvidersRead Lambda function.
- Enter
CloudProviders
for the API name. - Click Next.
- Enter
/clouds
for the Resource path. - Enter
GET
for the Method. - Click Next.
- In the Configure stages pane, enter
default
for the Stage name. - Click Next.
- On the Review and create* pane, click Create.
- 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
- Create a new Lambda Function. Name the Lambda Function
CloudProvidersWrite
. Use theNodejs 12.x
Runtime. Assign thelambda-dynamodb-cloudproviders-role
IAM Role. - Click the Create function button.
- Replace the contents of
index.js
in the Function code area with the contents of index.js. - Click the Save button.
- 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. - Click on the Test button.
- 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)
- Go to API Gateway Console.
- Click on APIs.
- Select CloudProviders.
- Select the /clouds resource.
- Under Actions, select Create Method.
- Enter
POST
and confirm. - Enter
CloudProvidersWrite
for the Lambda function and click Save. - With the POST method selected, click on Integration Request.
- Scroll down and select the Mapping Templates section.
- Choose the When there are no templates defined (recommended) radio button.
- Click on Add mapping template.
- Enter
application/json
for the Content-Type and click the confirm checkmark. - Copy the contents from mapping-template.json into the text body and click Save.
- 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)
- Go to API Gateway Console.
- Click on APIs.
- Select CloudProviders.
- Click on Routes.
- Click Create.
- On the Create a route pane, select POST from the method dropdown and enter
/post
for the route. - Click Create.
- Click on the POST route and click the Attach integration button.
- Click the Create and attach an integration button.
- On the Review and create* pane, click Create.
- Select Lambda Function radio button in the Integration with section.
- Choose the
CloudProvidersWrite
for the Lambda function in the Integration details section. - Click the Create button.
- 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/"}'