aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Use Existing S3 Bucket for "amplify add hosting" #1373

Open matwerber1 opened 5 years ago

matwerber1 commented 5 years ago

Is your feature request related to a problem? Please describe. We are unable to use existing S3 buckets for hosting the public website created by "amplify add hosting". My organization requires that public website buckets be created in advance by certain teams and following certain procedures/settings; the bucket created by amplify falls outside of this requirement.

Describe the solution you'd like When running "amplify add hosting", would like the prompts to ask whether a new or existing bucket should be created. If an existing bucket is selected, then amplify will not create/modify the bucket. Docs should be updated giving a brief overview of how users should configure the existing bucket in order for it to work with amplify.

Describe alternatives you've considered Alternatives - allow amplify to create a bucket from "amplify add hosting", then delete the newly-created bucket and manually edit the amplify config files to use/point to the pre-existing bucket that we want to use.

Additional context N/A

PhilosoD00M commented 4 years ago

I would also like to see amplify be able to use pre-existing S3 buckets. Because of our security policies, developers cannot create their own public S3 buckets.

swaminator commented 4 years ago

You can use Amplify Console for hosting your app with an existing S3 bucket. Checkout https://aws.amazon.com/blogs/mobile/deploy-files-s3-dropbox-amplify-console/

matwerber1 commented 4 years ago

@swaminator that's a good call-out, but that only applies to apps that when you're using the AWS Amplify Console / hosting service.

My issue is related to using the Amplify CLI, not the Amplify Console, service to set up hosting.

Such as:

amplify add hosting (dev)
amplify push
dannygoncalves commented 3 years ago

Incredible how still today this doesn't have a potential solution, I'm stuck on the same thing, can't push to an existing bucket (which is a requirement) or don't know-how. @matwerber1 did you figured out how to do this?

davegravy commented 3 years ago

Also stuck on this

matwerber1 commented 3 years ago

@dannygoncalves I'm not an authoritative answer, but I think the workaround for this is to just create your own separate deployment mechanism.

In other words, you develop your app locally, you can use amplify CLI to add backend features, etc... but when it comes time to publish, you would do something along the lines of npm run build and then use the S3 CLI to copy the frontend assets to your existing deployment bucket configured for S3 static hosting. And of course, you'd probably want the bucket (and related resources, like CloudFront) defined as infra-as-code with CloudFormation, Terraform, CDK, etc. and, you could consider setting up CI/CD whereby a push to your code repository would trigger the build and copy commands. At least, that's how I'd do it (I know just use the Amplify Console for hosting).

davegravy commented 3 years ago

@dannygoncalves I'm not an authoritative answer, but I think the workaround for this is to just create your own separate deployment mechanism.

In other words, you develop your app locally, you can use amplify CLI to add backend features, etc... but when it comes time to publish, you would do something along the lines of npm run build and then use the S3 CLI to copy the frontend assets to your existing deployment bucket configured for S3 static hosting. And of course, you'd probably want the bucket (and related resources, like CloudFront) defined as infra-as-code with CloudFormation, Terraform, CDK, etc. and, you could consider setting up CI/CD whereby a push to your code repository would trigger the build and copy commands. At least, that's how I'd do it (I know just use the Amplify Console for hosting).

Agree with this. From what I can gather from having only been immersed in it for a few days now, Amplify doesn't generally enable any new functionality, it just automates and encapsulates the things you can do without it. So workarounds like you propose sort of defeat the whole point of using the service.

matwerber1 commented 3 years ago

@davegravy for the most part, I agree.... though really, Amplify is three things... the deployment framework (Amplify CLI), the hosting service, and the libraries. Depending on my project, I definitely still appreciate using just one or two of the individual components. For example, I really like the Amplify Auth JS library to abstract away a lot of the work for Cognito intregration. There's nothing to stop one from using the libraries or the hosting framework without using the deployment CLI.