-1

I have a simple DynamoDB on AWS with a table which I can view test data 'Items' from the DynamoDB console also via a standalone client called Dynobase.

Now I want to create a simple webpage hosted on Lightsail that contains a HTML table to display the data. I would like to connect to the DynamoDB using PHP then issue a query, tabulating the response.

Can someone point me at an example of how to do this? - The AWS documentation is quite confusing.

This is the code Link to the code I am running on my Lightsail instance. I have added <?php at the top of the file and ?> at the bottom. I am testing the code via my web browser xx.xx.xx.xx/MoviesCreateTable.php

This is the error I am getting->
Unable to create table: Error executing "CreateTable" on "http://localhost:8000"; AWS HTTP error: cURL error 7: Failed to connect to localhost port 8000: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8000

Many Thanks Andy

Andys
  • 43
  • 6
  • How to do what specifically? Where are you stuck? – Mark B May 10 '21 at 20:24
  • It's the same as writing the PHP to run on your local computer or anywhere else, there is nothing special about the Lightsail server that would make the code different. Are you saying you can't find any examples or documentation for using DynamoDB in PHP? – Mark B May 10 '21 at 20:34
  • Please edit your question to include your code, and the error message you are getting. This is the specific info that should have been included in your question originally. – Mark B May 10 '21 at 20:42
  • That tutorial is using a local copy of DynamoDB running on port `8000`. Did you set that up prior to testing that code? – Mark B May 10 '21 at 20:58
  • No local copy on the Lightsail Instance as I would like to connect to my pre-existing DynamoDB hosted on AWS – Andys May 10 '21 at 21:01
  • Delete the `endpoint` setting in the DynamoDB configuration so it will stop looking for a local instance. – Mark B May 10 '21 at 21:08
  • 1
    If you go through the entire tutorial they eventually tell you to remove the `endpoint` setting https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.PHP.Summary.html but that tutorial is very lacking on the details. – Mark B May 10 '21 at 21:09
  • Unable to create table: Error executing "CreateTable" on "https://dynamodb.eu-west-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://dynamodb.eu-west-1.amazonaws.com` resulted in a `400 Bad Request` response: – Andys May 10 '21 at 21:12
  • {"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User: arn:aws:sts::050883770095:assumed-role/Amazo (truncated...) AccessDeniedException (client): User: arn:aws:sts::050883770095:assumed-role/AmazonLightsailInstanceRole/i-07447e48dd404c34a is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:eu-west-1:050883770095:table/Movies - {"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User: arn:aws:sts::050883770095:assumed-role/AmazonLightsailInstanceRole/i-07447e48dd404c34a is not authorized to perform: dynamodb:CreateTable on r – Andys May 10 '21 at 21:13
  • Do I need to give the lightsail role access to dynamoDb – Andys May 11 '21 at 06:46
  • You can't modify roles in lightsail. You have no control over the IAM roles lightsail instances have. They are basically EC2 instances running in some AWS account that you have no visibility into. You would have to configure AWS credentials some other way, like through environment variables. – Mark B May 11 '21 at 12:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232220/discussion-between-andys-and-mark-b). – Andys May 11 '21 at 12:47

1 Answers1

0

It turned out that the tutorial here ([Link to the code]) was very useful.

The main changes I made to enable the examples to work on my lightsail instance were to remove the endpoint line from the credentials.

Then I created a new Lightsail user and attached a policy o that user that had lightsail access and DynamoDB access.

Next, using the aws cli on the lightsail box I configured it for the new lightsail user.

This worked for me.

Andys
  • 43
  • 6