0

I'm struggling to find an easy way to push my backend code from GitLab to AWS EC2. All tutorials and guides I found are really tiresome which is very strange to me because for uploading code to AWS S3 it's a piece of cake. Here is my gitlab-ci.yml for S3 where I upload my frontend:

variables:
  S3_BUCKET_PROD: "production-frontend"
  S3_BUCKET_STAGE: "stage-frontend"

deploy-server-stage:
  image: python:3.5
  environment: stage
  script:
  - pip install awscli
  - aws s3 cp dist s3://$S3_BUCKET_STAGE/ --recursive
  only:
    - stage

deploy-server-production:
  image: python:3.5
  environment: production
  script:
  - pip install awscli
  - aws s3 cp dist s3://$S3_BUCKET_PROD/ --recursive
  only:
    - master

While for EC2 it's a journey through through .pem's, chmod's and even separate scripts written in .sh file to pull code locally. Really, most tutorials are way to complicated for such common task.

It can't be that hard (like here for example) - I hope there is someone who managed it in easy and classy way. Right now the easiest way is to push it through ssh from my machine, but it really shouldn't be like that.

In case if that matters: I'm talking about Node.js files so nothing fancy really.

jean d'arme
  • 3,011
  • 3
  • 24
  • 50
  • 1
    Rather than 'pushing' to an EC2 instance, it is much better for the EC2 instance to 'pull'. It is also better from a security perspective. The hard bit is triggering the pull. This could be as simple as regularly checking S3 for changes, or creating some method to trigger code that does the pull. – John Rotenstein Jan 06 '19 at 08:42
  • Pulling seems reasonable, but I'm still getting why I have to use S3 to update EC2 :) Like, AWS seems so sophisticated that I'm surprised we have to do such complicated things with it. Would that be easier if I'd move to Google Cloud maybe? – jean d'arme Jan 06 '19 at 10:25
  • An Amazon EC2 instance is just a normal computer running Windows or Linux. You can do anything on them that you can do on a normal computer. The advantage is that you can take advantage of other AWS services, such as S3 for storage, SQS for queueing, SNS for notifications, etc. – John Rotenstein Jan 06 '19 at 10:34

0 Answers0