Bill Koch
06/11/2021, 6:37 PM// MyStack.ts
import * as sst from "@serverless-stack/resources";
import { Deployment, RestApi, Stage } from "@aws-cdk/aws-apigateway";
export default class MyStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const apiGateway = RestApi.fromRestApiAttributes(this, "MyRestApi", {
restApiId: "8w6b74ksx0",
rootResourceId: "6lhf5t9hje",
});
const deployment = new Deployment(this, `${scope.stage}-deployment`, {
api: apiGateway
});
const stage = new Stage(this, `${scope.stage}-stage`, {
deployment: deployment,
stageName: scope.stage
});
apiGateway.deploymentStage = stage;
// Create a HTTP API
const api = new sst.ApiGatewayV1Api(this, "Api", {
restApi: apiGateway,
importedPaths: {
"/serverless": "tvg3ia"
},
routes: {
"GET /serverless/hello": "src/lambda.handler",
},
});
}
}
Any help would be greatly appreciated!Bill Koch
06/11/2021, 6:40 PMBill Koch
06/11/2021, 6:40 PMFrank
apiGateway.deploymentStage = stage;
I’m not sure if you can set the deploymentStage
on an imported RestApi.Frank
Stage
and Deployment
, why not creating a new RestApi instead of importing one?Bill Koch
06/11/2021, 7:29 PMBill Koch
06/11/2021, 7:30 PMFrank
Frank
Bill Koch
06/11/2021, 7:59 PMtest
stage and created a new test
stage via the AWS console:Bill Koch
06/11/2021, 8:01 PMsst deploy --stage test
, and the output shows there were no changes to deploy:
npx sst deploy --stage test
Preparing your SST app
Detected tsconfig.json
Transpiling source
Linting source
/Users/kochwm/dev/sst/restapi-example/lib/MyStack.ts
17:11 warning 'stage' is assigned a value but never used @typescript-eslint/no-unused-vars
25:11 warning 'api' is assigned a value but never used @typescript-eslint/no-unused-vars
✖ 2 problems (0 errors, 2 warnings)
Running type checker
Building Lambda function src/lambda.handler
Linting Lambda function source
/Users/kochwm/dev/sst/restapi-example/src/lambda.ts
4:3 warning 'event' is defined but never used @typescript-eslint/no-unused-vars
✖ 1 problem (0 errors, 1 warning)
Type checking Lambda function source
Deploying stacks
✅ test-restapi-example-my-stack (no changes)
Stack test-restapi-example-my-stack
Status: no changes
Frank
Bill Koch
06/11/2021, 8:03 PMtest
stage in the AWS console:Bill Koch
06/11/2021, 8:07 PMtest
stage is gone in the AWS Console 🤔Frank
Bill Koch
06/11/2021, 8:13 PMFrank
npm run remove
to remove ur stack
3. Setup Stage/Deployment in ur AWS cnosole manually
4. npm run deploy
to deploy ur stackFrank
test
stage was created by CF, and then it was manually removed and added in AWS console, CF doesn’t know that.. so it removed the one u createdBill Koch
06/11/2021, 9:06 PMBill Koch
06/11/2021, 9:09 PMAWS::ApiGateway::Deployment
or AWS::ApiGateway::Stage
in the generated CFFrank
Bill Koch
06/11/2021, 9:12 PMAWS::ApiGateway::Deployment
and AWS::ApiGateway::Stage
are in the generated CF when I don't try to import an existing RestApi (have SST generate one for me)Bill Koch
06/11/2021, 9:12 PMFrank
RestApi
into sst.ApiGatewayV1Api
? Did you have to create an Api Gateway Deployment resource in ur CDK code, ie.
const importedApi = RestApi.fromRestApiAttributes(...)
const deployment = new Deployment(this, `deployment`, {
api: importedApi
});
Ross Coundon
06/12/2021, 6:38 AMFrank
Frank
new sst.ApiGatewayV1Api(this, "Api", {
restApi: apig.RestApi.fromRestApiAttributes(this, "ImportedApi", {
restApiId: "2x7syiara1",
rootResourceId: "rz22vbtuih",
}),
routes: {
"GET /new": "src/lambda.main",
},
});
The above should work. No need to create a Stage
or Deployment
construct.Frank
Bill Koch
06/15/2021, 5:54 PMBill Koch
06/15/2021, 5:56 PMnpx sst deploy --stage dev
and then attempt to deploy a different stage npx sst deploy --stage tst
, I get this error:
CREATE_FAILED | AWS::ApiGateway::Resource | ApiResourceserverlesshello57FB95D2 Another resource with the same parent already has this name: hello (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: 1cb91abb-1607-48a3-8d82-d9df4eb13f28; Proxy: null)
Bill Koch
06/15/2021, 5:56 PMFrank
RestApi.fromRestApiAttributes(this, "MyRestApi", {
restApiId: "8w6b74ksx0",
rootResourceId: "6lhf5t9hje",
});
I’m guessing the restApiId
and rootResourceId
should be different for different stages?Bill Koch
06/15/2021, 7:27 PMsst deploy --stage feature-ABC-123
)
• somedomain.com/feature-XYZ-456 (sst deploy --stage feature-XYZ-456
)Bill Koch
06/15/2021, 7:27 PMFrank
Frank