AWS Amplify + bitbucket deployment issue

Viewed 1088

I'm trying to deploy Amplify project using bitbucket repo with the frontend. At the deploying stage Amplify CLI asks for OAuthToken (which cannot be found anywhere in bitbucket). OAuth consumer has key and secret and both are not accepted by Amplify CLI.

Error i'm getting is:

There was an issue setting up your repository.   
Please try again later.({"type": "error",        
"error": {"message": "Access token expired."}})  
(Service: Amplify; Status Code: 400; Error Code: 
BadRequestException; Request ID:                 
ceced480-e38d-4c44-a1db-ad2eb50e34a8; Proxy:     
null) 

I might be doing something wrong here. But hours of googling didnt helped me.

Please advice. Big thanks in advance!

1 Answers

The solution is to setup OAuth Consumers (key and secret) in your bitbucket account, but there are some specific steps you have to follow.

Click on your account profile name -> settings. Under OAuth Consumers, click add consumers.

  • Set callback url to http://localhost:3000 Note: this was never used, but couldnt get it to work without setting something
  • Check 'This is private consumer'

Permissions:

  • Repositories -> Admin
  • Webhooks -> Read and Write
  • Pull Requests -> Read

Once created, make a note of the key and secret, as it will be used in the next step.

Open terminal (replacing KEY and SECRET) and run:

curl -X POST -u "KEY:SECRET" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials

This will return an access_token which you should copy.

Now, this threw me, because in AWS, you can supply an access token or an oath token. Since we are using OAuth, even though the returned token is called access_token, in aws we need to add it to the OAuthToken field.

In Cloudformation, it looks as follows (AWS CLI uses similarly named fields, so should also work there).

  Type: AWS::Amplify::App
  Properties:
    Name: MyApp
    Repository: https://bitbucket.org/USERNAME/REPO_NAME
    OauthToken: ACCESS_TOKEN # token returned from terminal command
Related