eduardo3g / twitter

A serverless Twitter built with some cool stuff, such as the Serverless Framework, AppSync (GraphQL), Lambda, DynamoDB, Cognito, Kinesis Firehose, and Algolia ☁️
MIT License
42 stars 6 forks source link

Layers deployment bucket does not exist #2

Open eduardo3g opened 3 years ago

eduardo3g commented 3 years ago

The error below is thrown when the command npx sls deploy is executed. This comes from the serverless-layers plugin because it could not find an S3 Bucket to push the layers during the deployment.

image

eduardo3g commented 3 years ago

This error occurs because, during the deployment with Serverless Framework, it goes to SSM Parameter Store to retrieve an S3 bucket name - which is the bucket that'll store the dependencies files, etc.

There are currently three approaches to deploy the back-end application:

Easiest way - Removing Serverless Layers feature

  1. Open serverless.yml file.
  2. Comment lines 8, 28 and 29.
  3. Run the command npx sls deploy.

Manually creating an S3 Bucket for your layers and SSM Parameter

  1. Open S3 and create a bucket following the pattern twitterappsync-layer-deployment-bucket-<an-unique-identifier>. Remember that S3 is a global service, so S3 bucket names must be unique.
  2. Save the S3 bucket name on your notes. For example, twitterappsync-layer-deployment-bucket-ASDKJL1d.
  3. Open AWS Systems Manager and select Parameter Store on the left menu
  4. Create a parameter named twitterappsync/dev/layer-deployment-bucket. The parameter type can be String.
  5. On the parameter value, copy the S3 bucket name you have in your notes.
  6. Once S3 and SSM is set up, deploy your app: npx sls deploy

The ideal solution

Unfortunately, there's not a workaround via Serverless Framework to first deploy an S3 Bucket and SSM Parameter, the deploy the app using serverless layers.

One good approach is combining Serverless Framework with some IaC (Infrastructure as Code) tool such as Terraform. I'd go with the following solution:

  1. Create a Terraform script using HCL, that'll create an S3 Bucket and an SSM Parameter.
  2. Builder a shell script to run both deployments commands: Terraform first and then Serverless Framework.
  3. Execute the shell script locally or on a CI/CD pipeline.
pchauhan77 commented 3 years ago

can you solve it and share running application and please share .env example ? Please add terraform also if need

eduardo3g commented 3 years ago

Hi @pchauhan77, adding the Terraform step is on my roadmap but there is not an ETA yet.

I recommend you to follow the second option ("Manually creating an S3 Bucket for your layers and SSM Parameter") for now.

Regarding the .env file, there's already a closed issue for that. After you're able to deploy the application by running npx sls deploy, run the command npm run exportEnv and it'll generate a .env file in your root directory.