{"id":19817619,"url":"https://github.com/adamelliotfields/learning-serverless","last_synced_at":"2025-07-26T00:12:48.166Z","repository":{"id":145687120,"uuid":"357737099","full_name":"adamelliotfields/learning-serverless","owner":"adamelliotfields","description":"My notes from learning the Serverless Framework","archived":false,"fork":false,"pushed_at":"2021-04-14T01:34:50.000Z","size":392,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T08:12:10.433Z","etag":null,"topics":["serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamelliotfields.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-14T01:30:13.000Z","updated_at":"2023-08-02T19:18:40.000Z","dependencies_parsed_at":"2023-06-04T18:15:28.233Z","dependency_job_id":null,"html_url":"https://github.com/adamelliotfields/learning-serverless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamelliotfields%2Flearning-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamelliotfields%2Flearning-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamelliotfields%2Flearning-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamelliotfields%2Flearning-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamelliotfields","download_url":"https://codeload.github.com/adamelliotfields/learning-serverless/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241173914,"owners_count":19922204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["serverless"],"created_at":"2024-11-12T10:13:11.004Z","updated_at":"2025-02-28T15:23:32.804Z","avatar_url":"https://github.com/adamelliotfields.png","language":"JavaScript","readme":"# `learning-serverless`\n\nNotes from my experience learning [Serverless Framework](https://www.serverless.com).\n\nThis is not intended to be a guide, so it might not make sense to you. Feel free to open an [issue](https://github.com/adamelliotfields/learning-serverless/issues)\nif you'd like to suggest something or need help otherwise.\n\n## What is Serverless Framework?\n\nServerless Framework is a toolkit for building serverless applications. By simply providing a few\nlines of YAML to the Serverless CLI, you can easily provision cloud resources on AWS. Serverless was\noriginally known as JAWS (JavaScript AWS).\n\nThe benefit of using Serverless over something like Vercel is that with Serverless you're\nprovisioning AWS resources that you have complete control over and that can easily be connected to\nother AWS resources like Cognito or a database. If you need a resource that is not supported by\nServerless natively, they allow you provide a CloudFormation template so you can still accomplish\neverything with one tool. When you're using a service like Vercel or Heroku, you are sacrificing\nthat control for simplicity.\n\n## What are Serverless Components?\n\nServerless Components are a new feature from Serverless. Each component is a JavaScript class that\nimplements an interface to provision cloud resources using user-defined settings. There are quite a\nfew official components, and anyone can make a new component and upload it to the Serverless\nComponent Registry.\n\nComponents are very easy to use, but the official ones don't support every possible configuration\nsetting that you get when using the old format. For example, I did not see a way to add an event\ntrigger when using the `aws-lambda` component. Also the [`serverless-finch`](https://github.com/fernando-mc/serverless-finch)\nplugin has much more options than the `website` component.\n\nComponents are also executed in the cloud, not locally. When you deploy a traditional Serverless\nservice or stack, a CloudFormation template and Lambda zip package are uploaded to S3. This doesn't\nhappen when you deploy a Serverless Component and I _think_ it's because Components don't use\nCloudFormation.\n\n## Getting Started\n\n\u003e Note that you'll need a domain either registered with Route 53 or at least managed by Route 53.\n\nFirst log into your AWS account.\n\nNext you'll need to create a free account at \u003chttps://app.serverless.com\u003e.\n\nNow within the Serverless dashboard, click \"Org\" then \"Providers\" then click the \"add\" button. Then\nclick the \"create role\" button to be redirected to AWS CloudFormation. Once you click\n\"Create Stack\", you'll be redirected back to Serverless and should see your AWS provider.\n\n\u003e Note that by default, this role is given `AdministratorAccess` permission.\n\nYou're also going to need to have the AWS CLI and Serverless CLI installed:\n\n```bash\n# First install and configure AWS (you'll need your access key ID and secret)\nwget https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -O /tmp/aws.zip\nunzip /tmp/aws.zip -d /tmp\nrm /tmp/aws.zip\nsudo /tmp/aws/install\nrm -rf /tmp/aws\naws configure\n\n# Now install Serverless and log-in (this will open your default web browser)\nnpm i -g serverless\nserverless login\n```\n\n## Examples\n\n### Static Website\n\nThe [website](https://github.com/serverless-components/website) component will deploy your web app\nto an S3 bucket and create a Cloudfront distribution.\n\nIf your domain name is managed by Route 53, it will also create the necessary DNS records and an\nACM HTTPS certificate. If the domain name you specify is a naked domain (no subdomain) it will\nalso create a record for the `www` subdomain; likewise, if the domain you specify has a `www`\nsubdomain, it will create a naked domain record as well.\n\n```bash\ncd website-component-example\n# The debug option shows you exactly what Serverless is doing.\nsls deploy --debug\n```\n\nRun `sls remove` to remove the created resources. It will take a little time for the Cloudfront\ndistribution to be disabled and you'll have to delete it manually. The ACM certificate will remain\nas it can be reused (it's a wildcard subdomain).\n\n### IAM Role\n\nThe [aws-iam-role](https://github.com/serverless-components/aws-iam-role) component will create an\nIAM role. You can provide either a single policy ARN or an inline policy statement. This component\nis useful for creating roles you can use in your other components.\n\n```bash\ncd iam-role-example\nsls deploy --debug\n```\n\n### Express Application\n\nThe [`express`](https://github.com/serverless-components/express) component allows you to deploy an\nExpress application as a Lambda function.\n\nIt works by wrapping your Express app in the [`serverless-http`](https://www.npmjs.com/package/serverless-http)\nlibrary. This allows you to use middleware and define routes like you normally would in a\ntraditional Express app.\n\nFor this to work, you want to separate your `app` from your `server`, and you also must set\n`\"main\": \"app.js\"` in `package.json`.\n\nThe component will also create an API Gateway HTTP API pointing to your Express Lambda and a custom\ndomain with a ACM HTTPS certificate.\n\n```bash\ncd express-example\nsls deploy --debug\n```\n\n### GraphQL API\n\nThe [`graphql`](https://github.com/serverless-components/graphql) component will create a Lambda\nfunction and AppSync API using the GraphQL schema and resolvers you provide. The API will be secured\nwith an API Key. It will also create a CloudFront distribution to cache your responses as well as a\ncustom domain with an ACM HTTPS certificate.\n\n```bash\ncd graphql-example\nsls deploy --debug\n```\n\nIf you get a KMS `CreateGrant` error, you might have to wait a few minutes and try deploying again.\nYou can read more about this [here](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html).\n\n### Lambda Function\n\nThe [aws-lambda](https://github.com/serverless-components/aws-lambda) component will create a Lambda\nfunction. As of right now I found this component to be pretty limited. The runtime is hard-coded at\nNode v12 and you cannot add any event triggers (in other words, it just uploads your function to\nLambda with no way to invoke it). To get it to even work, I had to create a custom IAM Role because\nthe default role it uses didn't exist on my account (`AWSLambdaFullAccess` should be\n`AWSLambda_FullAccess`). This component is probably a work-in-progress.\n\nTo that end, this example uses the traditional (non-component) syntax. It will create a Lambda\nfunction and an API Gateway API pointing to the Lambda. Because this is not using a Serverless\nComponent, it will upload a CloudFormation template and a zip containing your Lambda to S3.\n\n```bash\ncd lambda-example\n# The --debug option doesn't work when deploying non-components.\nsls deploy\n```\n\n### NextJS Application\n\nThe [`serverless-nextjs`](https://github.com/serverless-nextjs/serverless-next.js) component will\nbuild your NextJS and deploy the static pages and resources to S3 and create Lambda functions for\nthe dynamic pages and API. A CloudFront distribution will be created and configured to point at your\nS3 bucket and Lambdas. Finally, it will also configure your custom domain with Route 53 and\nprovision a HTTPS certificate from ACM.\n\nNote that this component is not maintained by the Serverless team and it is currently using the\nComponents beta syntax (so it looks different than the other examples and you cannot run\n`sls deploy`).\n\nAlso note that running `sls remove` threw an error. The CloudFront distribution was disabled and the\nS3 bucket was removed, but the Route 53 domain and the 2 Lambda functions remained and had to be\ndeleted manually. Follow [this guide](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-delete-replicas.html)\nto see how to delete a Lambda@Edge function.\n\n```bash\ncd nextjs-example\n# Run the serverless command with no arguments or options.\nsls\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamelliotfields%2Flearning-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamelliotfields%2Flearning-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamelliotfields%2Flearning-serverless/lists"}