From 2ade40fe765c8b39f96d1d52c3d6b3da4442e760 Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 09:16:22 +0800 Subject: [PATCH 1/6] Update index.md Add instructions on how to handle custom ids --- .../serverless-framework/index.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index 727600a1d9..a2c79edb1c 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -203,6 +203,37 @@ custom: When this flag is set, the lambda code will be mounted into the container running the function directly from your local directory instead of packaging and uploading it. +## Custom API deployment IDs +By default localstack generates random dployment ids for the API gateway which in turn get populated into the endpoint URLs. As these IDs can literally change every time you deploy (depending on your setup) This makes continual local development practically impossibly in situations where you rely on consistant urls (eg the url for your api for your frontend code) + +localstack provides a method to use a fixed custom id instead by passing a tag _custom_id_ to the API during creation. It has to be done during creation and it has to be on either the v2 API or the v1 RestApi. + +Serverless can do this out of the box with resource extensions. See below for the v1/v2 implementation. + +This will produce endpoints like +http://localhost:4566/restapis/mytag/development/_user_request_ (v1) + +rather than a continually changing ID +http://localhost:4566/restapis/jh345798dx/development/_user_request_ + +``` +resources: + extensions: + ApiGatewayRestApi: #for v1 + Properties: + Tags: + - Key: _custom_id_ + Value: mytag + + MyHTTPApi: #for v2 + Properties: + Tags: + - Key: _custom_id_ + Value: mytag + +``` + + ## Ran into trouble? If you run into any issues or problems while integrating LocalStack with your Serverless app, please [submit an issue](https://github.com/localstack/serverless-localstack/issues). From 2feac1900c4c2cbd8f4cbedc33351d9aec7489ac Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 09:22:23 +0800 Subject: [PATCH 2/6] Update index.md fix typo --- .../en/user-guide/integrations/serverless-framework/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index a2c79edb1c..f1d0c6e5d2 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -204,7 +204,7 @@ custom: When this flag is set, the lambda code will be mounted into the container running the function directly from your local directory instead of packaging and uploading it. ## Custom API deployment IDs -By default localstack generates random dployment ids for the API gateway which in turn get populated into the endpoint URLs. As these IDs can literally change every time you deploy (depending on your setup) This makes continual local development practically impossibly in situations where you rely on consistant urls (eg the url for your api for your frontend code) +By default localstack generates random deployment ids for the API gateway which in turn get populated into the endpoint URLs. As these IDs can literally change every time you deploy (depending on your setup) This makes continual local development practically impossible in situations where you rely on consistant urls (eg the url for your api for your frontend code) localstack provides a method to use a fixed custom id instead by passing a tag _custom_id_ to the API during creation. It has to be done during creation and it has to be on either the v2 API or the v1 RestApi. From ceb28c32afe03046b7cd1fe8ff5ffee48996108c Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 09:38:46 +0800 Subject: [PATCH 3/6] Update index.md Also add details about running hot-reload bucket --- .../serverless-framework/index.md | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index f1d0c6e5d2..63a5376cfb 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -216,7 +216,7 @@ http://localhost:4566/restapis/mytag/development/_user_request_ (v1) rather than a continually changing ID http://localhost:4566/restapis/jh345798dx/development/_user_request_ -``` +```yaml resources: extensions: ApiGatewayRestApi: #for v1 @@ -232,7 +232,35 @@ resources: Value: mytag ``` - + +## Hot reload +To get hot-relaod up and running quickly. put the following into a script before you run sls deploy. + +You need the region set to the same region you are using otherwise the bucket and ssm param can't be found by the sls deployment + +- note: this requires the localstack awslocal cli to be installed + +```bash +awslocal s3api create-bucket --bucket hot-reload --create-bucket-configuration LocationConstraint=ap-southeast-2 +AWS_DEFAULT_REGION=ap-southeast-2 awslocal ssm put-parameter \ + --name "/serverless-framework/deployment/s3-bucket" \ + --type "String" \ + --value "{\"bucketName\":\"hot-reload\",\"bucketRegion\":\"ap-southeast-2\"}" +``` + +Then in your serverless.yaml Use the custom variables to set the names. this uses the default option to set the name to the same as serverless does when deploying + +```yaml + +custom: + development: + bucket: 'hot-reload' + +provider: + deploymentBucket: ${self:custom.${self:provider.stage}.bucket, serverless-deployment-bucket-${self:service}-${self:provider.stage}} + +``` + ## Ran into trouble? From 4f6ce9460107343dbca4987639be6b2d36bffe6a Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 09:39:51 +0800 Subject: [PATCH 4/6] Update index.md fix heading sizes --- .../en/user-guide/integrations/serverless-framework/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index 63a5376cfb..61146eecf5 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -203,7 +203,7 @@ custom: When this flag is set, the lambda code will be mounted into the container running the function directly from your local directory instead of packaging and uploading it. -## Custom API deployment IDs +### Custom API deployment IDs By default localstack generates random deployment ids for the API gateway which in turn get populated into the endpoint URLs. As these IDs can literally change every time you deploy (depending on your setup) This makes continual local development practically impossible in situations where you rely on consistant urls (eg the url for your api for your frontend code) localstack provides a method to use a fixed custom id instead by passing a tag _custom_id_ to the API during creation. It has to be done during creation and it has to be on either the v2 API or the v1 RestApi. @@ -233,7 +233,7 @@ resources: ``` -## Hot reload +### Hot reload To get hot-relaod up and running quickly. put the following into a script before you run sls deploy. You need the region set to the same region you are using otherwise the bucket and ssm param can't be found by the sls deployment From 2959be8d31bf342dffd9f489f2f1006f669fc60a Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 09:41:37 +0800 Subject: [PATCH 5/6] Update index.md typos --- .../user-guide/integrations/serverless-framework/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index 61146eecf5..2fd2c2ea37 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -234,9 +234,9 @@ resources: ``` ### Hot reload -To get hot-relaod up and running quickly. put the following into a script before you run sls deploy. +To get hot-reload up and running quickly, put the following into a script before you run sls deploy. -You need the region set to the same region you are using otherwise the bucket and ssm param can't be found by the sls deployment +You need the region set to the same region in your config otherwise the bucket and ssm param can't be found by the sls deployment - note: this requires the localstack awslocal cli to be installed @@ -248,7 +248,7 @@ AWS_DEFAULT_REGION=ap-southeast-2 awslocal ssm put-parameter \ --value "{\"bucketName\":\"hot-reload\",\"bucketRegion\":\"ap-southeast-2\"}" ``` -Then in your serverless.yaml Use the custom variables to set the names. this uses the default option to set the name to the same as serverless does when deploying +Then in your serverless.yaml use the custom variables to set the names. This uses the default option to set the name to the same as serverless does when deploying ```yaml From 974df8d7fc5f5f726ab1042b38ae0f5ec9a358bd Mon Sep 17 00:00:00 2001 From: fridaystreet Date: Wed, 6 Nov 2024 10:02:14 +0800 Subject: [PATCH 6/6] Update index.md add newer url reference --- .../en/user-guide/integrations/serverless-framework/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/en/user-guide/integrations/serverless-framework/index.md b/content/en/user-guide/integrations/serverless-framework/index.md index 2fd2c2ea37..2681586e9d 100644 --- a/content/en/user-guide/integrations/serverless-framework/index.md +++ b/content/en/user-guide/integrations/serverless-framework/index.md @@ -213,6 +213,9 @@ Serverless can do this out of the box with resource extensions. See below for th This will produce endpoints like http://localhost:4566/restapis/mytag/development/_user_request_ (v1) +or for the newer localstack +http://localhost:4566/_aws/execute-api/mytag/development + rather than a continually changing ID http://localhost:4566/restapis/jh345798dx/development/_user_request_