This week, I spent a lot of time trying to connect to databases. Or rather, I wasted a lot of time trying to connect to databases. An AWS Amplify application caused me quite a headache, so I wanted to provide a simple walkthrough to help troubleshoot some of the issues I was facing.
Prerequisites
To start, there are three packages that you will need get get things going: 1. @aws-amplify-cli; 2. @aws-amplify; 3. the most recent version of AWS CLI. You will also need an AWS account.
Getting Going
I was working with an existing Github repo, so I cloned that repo to my local machine and accessed a working branch. To configure access to the AWS resources, you will need to run amplify configure
. This command requires you to log into your AWS account and configure the access permissions through an IAM account. When going through these steps, you will be prompted to set a region. It is essential that the AWS region you choose matches the region configured in the application. You can find this information in the repo's team-provider-info.json
You will also have to enter credentials for the IAM account that are produced in the AWS management console. These include an access key and a secret key. Take note of these in a secure location, though you can always produce a new one in the event that you lose it.
In theory, everything should be working from here and you can just run amplify init
to connect things. When I ran amplify init, I hit the following error.
Initializing your environment: dev(node:22264) UnhandledPromiseRejectionWarning: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
This is one of those programming things where you want to beat your head against a wall. I just told you the access key, why do you have to lose it? I tried going through the amplify configure
steps again, to no avail.
(An aside on amplify configure
. The amplify configure
command menu creates the impression you are always adding a new user, when in fact it is a way of updating a user (see this pull request for a more thorough discussion.)
In the prerequisites, I mentioned installing the AWS CLI tools. This allowed me to diagnosis and fix the problem. If you run aws configure
, it will show you the last 4 characters of both the saved access key ID and secret access key, as well as the selected region. If any of this looks different from what you input aws configure
, this is the place to change it. I updated the values here, and voila. I ran amplify init
, and things were working.
TL;DR
In summary, ensure you have the prerequisites. Run amplify configure
, then amplify init
and then run your app. Run aws configure
if things are not going right and then check your credentials.
Top comments (0)