aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.47k stars 3.82k forks source link

(aws-cdk/aws-amplify): Add a sourceCodeProvider for bitbucket. Currently only supports GitLab, GitHub and CodeCommit #12955

Open jaswanthm opened 3 years ago

jaswanthm commented 3 years ago

I am trying to setup a cdk pipeline to deploy a react app on AWS Amplify. Although, I am unable to use bitbucket as a source code provider.

Use Case

Setting up a new project on amplify through bitbucket is possible using the AWS console. But cdk doesn't have support for this.

Currently, as a workaround, I had to revert back to using CodePipeline and S3 bucket to deploy my react app through cdk, which isn't ideal.

Proposed Solution

Create a new source code provider for bitbucket like the one that already exists for Github, Gitlab and CodeCommit - https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-amplify.GitHubSourceCodeProvider.html


This is a :rocket: Feature Request

jogold commented 3 years ago

@jaswanthm in the meantime, you can unlock yourself like this:

const amplifyApp = new amplify.App(this, 'App', {
  // other props here
  sourceCodeProvider: {
    bind() {
      return {
        repository: 'https://...', // your bitbucket repo here
        oauthToken: SecretValue.secretsManager('my-token'), // with a token stored in Secrets Manager
      };
    },
  },
});
andreimcriss commented 3 years ago

@jaswanthm in the meantime, you can unlock yourself like this:

const amplifyApp = new amplify.App(this, 'App', {
  // other props here
  sourceCodeProvider: {
    bind() {
      return {
        repository: 'https://...', // your bitbucket repo here
        oauthToken: SecretValue.secretsManager('my-token'), // with a token stored in Secrets Manager
      };
    },
  },
});

I can't get this to work for Bitbucket Cloud. (works for Github) I tried both with App Passwords, which looks similar to the Github setup, and with OAuth2 key&secret combination. I'm getting "Access token expired" error when CDK tries to deploy the Amplify App.

Any idea what I'm doing wrong?

kornicameister commented 2 years ago

Same issue here. Any idea how hard it this to implement it?

kornicameister commented 2 years ago

In Python, I managed to do something like:

@jsii.implements(amplify.ISourceCodeProvider)
class BitbucketSourceProvider:

    def __init__(
        self,
        *,
        repository: str,
        access_key: str,
        secret_key: str,
    ) -> None:
        self._repo = repository
        self._access_key = access_key
        self._secret_key = secret_key

    def bind(self, app: amplify.App) -> amplify.SourceCodeProviderConfig:
        token = requests.post(
            'https://bitbucket.org/site/oauth2/access_token',
            auth=(self._access_key, self._secret_key),
            data={
                'grant_type': 'client_credentials',
            },
        ).json()['access_token']
        return amplify.SourceCodeProviderConfig(
            repository=self._repo,
            oauth_token=cdk.SecretValue.plain_text(token),
        )

This makes it possible to create an app with bitbucket as source provider.

wirjo commented 2 months ago

+1