Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@aws-cdk/aws-codecommit]: Repo can't find s3 bucket when deployed. #16958

Closed
fsmikedev opened this issue Oct 13, 2021 · 14 comments
Closed

[@aws-cdk/aws-codecommit]: Repo can't find s3 bucket when deployed. #16958

fsmikedev opened this issue Oct 13, 2021 · 14 comments
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@fsmikedev
Copy link

fsmikedev commented Oct 13, 2021

What is the problem?

I'm trying to create a codecommit repo with the contents of an s3 bucket.

Reproduction Steps

    const bucket = new s3.Bucket(this, `bucket-${account}`, {
      bucketName: `bucket-${account}`,
      autoDeleteObjects: true,
      publicReadAccess: true,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });

    const bucketDeploy = new s3deploy.BucketDeployment(this, `bucket-deploy-${account}`, {
      sources: [s3deploy.Source.asset(path.join(__dirname, "tmp"))],
      destinationBucket: bucket,
      destinationKeyPrefix: "test",
    });

    const repo = new codecommit.CfnRepository(this, "test-repo", {
      repositoryName: "test-repo",
      code: {
        branchName: "main",
        s3: {
          bucket: `bucket-${account}`,
          key: "test",
        },
      },
    });

    repo.node.addDependency(bucketDeploy);

What did you expect to happen?

The test repo would have contents deployed from the s3 bucket.

What actually happened?

An error when cdk deploy is called.

51/55 | 18:40:00 | CREATE_FAILED | AWS::CodeCommit::Repository | test-repo/test-repo (testrepoCE419A0A) Not Found (Service: Amazon S3; Status Code: 404; Error Code: 404 Not Found

CDK CLI Version

1.127.0

Framework Version

No response

Node.js Version

14.17.1

OS

Windows 10

Language

Typescript

Language Version

4.4.3

Other information

No response

@fsmikedev fsmikedev added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 13, 2021
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Oct 13, 2021
@skinny85
Copy link
Contributor

skinny85 commented Oct 13, 2021

Hey @fsmikedev,

thanks for opening the issue. Can you try this, and see if that helps?

    const repo = new codecommit.CfnRepository(this, "test-repo", {
      repositoryName: bucket.bucketName, // <--- here's the difference
      code: {
        branchName: "main",
        s3: {
          bucket: `bucket-${account}`,
          key: "test",
        },
      },
    });

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 13, 2021
@fsmikedev
Copy link
Author

Hi @skinny85, unfortunately that didn't change anything, still the same error.

@skinny85
Copy link
Contributor

Hmmm... I wonder if the problem are not missing permissions?

Can you try giving the codecommit.amazonaws.com Service Principal permissions to read from bucket, and see if that fixes the problem?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 15, 2021
@otaviomacedo otaviomacedo removed their assignment Oct 15, 2021
@otaviomacedo otaviomacedo added @aws-cdk/aws-codecommit Related to AWS CodeCommit and removed @aws-cdk/aws-s3 Related to Amazon S3 labels Oct 15, 2021
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Oct 15, 2021
@fsmikedev
Copy link
Author

I thought the same so I set publicReadAccess: true, I'll try the above, could you confirm the way to do that please? so I know I haven't applied it incorrectly, thanks.

@skinny85
Copy link
Contributor

Something like this:

        const bucket = new s3.Bucket(this, 'Bucket');
        bucket.addToResourcePolicy(new iam.PolicyStatement({
            actions: ['s3:*'],
            resources: [
                bucket.bucketArn,
                bucket.arnForObjects('*'),
            ],
            principals: [new iam.ServicePrincipal('codecommit.amazonaws.com')],
        }));

"s3:*" is too wide of course, but will do for a simple test.

@fsmikedev
Copy link
Author

Thanks.

Still no luck, same issue...I did find this post on stackoverflow, I've already added the BucketDeployment dependency to the repo.

https://stackoverflow.com/questions/63230623/aws-cdk-s3-to-codecommit-deployment

@skinny85
Copy link
Contributor

Hmm, this answer from that question is interesting: https://stackoverflow.com/a/64746898/10787899 (look at what it says about unzipping the contents).

@NGL321 NGL321 added the p2 label Oct 26, 2021
@NGL321
Copy link
Contributor

NGL321 commented Oct 26, 2021

Hey @fsmikedev,

Have you tried adding an ordering dependency as described in the the stackoverflow response? If that doesnt resolve the issue we can keep this issue open and look into it further.

@NGL321 NGL321 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 26, 2021
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 28, 2021
@fsmikedev
Copy link
Author

Hi @NGL321, yes that was the first thing I tried. I've checked my bucket layout and it matches what is expected by the codecommit repot bucket and key. I'm not sure what to try next.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Oct 28, 2021
@fsmikedev
Copy link
Author

Hi all, anymore suggestions for this? I need to get this working somehow, thanks.

@fsmikedev
Copy link
Author

...I've given up trying to get this to work. I'm using a lambda now.

@skinny85
Copy link
Contributor

skinny85 commented Dec 7, 2021

@fsmikedev did you do what this StackOverflow answer suggests? https://stackoverflow.com/questions/63230623/aws-cdk-s3-to-codecommit-deployment/64746898#64746898 (take special note of what is says about unzipping)

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 7, 2021
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 10, 2021
mergify bot pushed a commit that referenced this issue Dec 14, 2021
This repo introduces new properties to the constructor signature of the codecommit L2 Repository.
It allows users to upload code when creating a codecommit repository by leveraging the aws-s3-assets lib.
The user is able to upload whole directories at the moment.

The behaviour has a unit tests, and an integration test, which is passing (verified manually as well).

Closes #17967, provides a possible fix to #16958

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 15, 2021
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…17968)

This repo introduces new properties to the constructor signature of the codecommit L2 Repository.
It allows users to upload code when creating a codecommit repository by leveraging the aws-s3-assets lib.
The user is able to upload whole directories at the moment.

The behaviour has a unit tests, and an integration test, which is passing (verified manually as well).

Closes aws#17967, provides a possible fix to aws#16958

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

5 participants