Skip to content

Commit 63ac325

Browse files
authored
updates examples and scopes permissions (#7707)
1 parent 232b70a commit 63ac325

File tree

2 files changed

+18
-6
lines changed
  • src/pages/[platform]/build-a-backend/add-aws-services/rest-api

2 files changed

+18
-6
lines changed

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-http-api/index.mdx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ const httpLambdaIntegration = new HttpLambdaIntegration(
109109
// create a new HTTP API with IAM as default authorizer
110110
const httpApi = new HttpApi(apiStack, "HttpApi", {
111111
apiName: "myHttpApi",
112-
defaultAuthorizer: iamAuthorizer,
113112
corsPreflight: {
114113
// Modify the CORS settings below to match your specific requirements
115114
allowMethods: [
@@ -137,7 +136,15 @@ httpApi.addRoutes({
137136
// add a proxy resource path to the API
138137
httpApi.addRoutes({
139138
path: "/items/{proxy+}",
140-
methods: [HttpMethod.OPTIONS, HttpMethod.ANY],
139+
methods: [HttpMethod.ANY],
140+
integration: httpLambdaIntegration,
141+
authorizer: iamAuthorizer,
142+
});
143+
144+
// add the options method to the route
145+
httpApi.addRoutes({
146+
path: "/items/{proxy+}",
147+
methods: [HttpMethod.OPTIONS],
141148
integration: httpLambdaIntegration,
142149
});
143150

@@ -155,8 +162,9 @@ const apiPolicy = new Policy(apiStack, "ApiPolicy", {
155162
new PolicyStatement({
156163
actions: ["execute-api:Invoke"],
157164
resources: [
158-
`${httpApi.arnForExecuteApi("items")}`,
159-
`${httpApi.arnForExecuteApi("cognito-auth-path")}`,
165+
`${httpApi.arnForExecuteApi("*", "/items")}`,
166+
`${httpApi.arnForExecuteApi("*", "/items/*")}`,
167+
`${httpApi.arnForExecuteApi("*", "/cognito-auth-path")}`,
160168
],
161169
}),
162170
],

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api/index.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ const apiStack = backend.createStack("api-stack");
8989
const myRestApi = new RestApi(apiStack, "RestApi", {
9090
restApiName: "myRestApi",
9191
deploy: true,
92+
deployOptions: {
93+
stageName: "dev",
94+
},
9295
defaultCorsPreflightOptions: {
9396
allowOrigins: Cors.ALL_ORIGINS, // Restrict this to domains you trust
9497
allowMethods: Cors.ALL_METHODS, // Specify only the methods you need to allow
@@ -138,8 +141,9 @@ const apiRestPolicy = new Policy(apiStack, "RestApiPolicy", {
138141
new PolicyStatement({
139142
actions: ["execute-api:Invoke"],
140143
resources: [
141-
`${myRestApi.arnForExecuteApi("items")}`,
142-
`${myRestApi.arnForExecuteApi("cognito-auth-path")}`,
144+
`${myRestApi.arnForExecuteApi("*", "/items", "dev")}`,
145+
`${myRestApi.arnForExecuteApi("*", "/items/*", "dev")}`,
146+
`${myRestApi.arnForExecuteApi("*", "/cognito-auth-path", "dev")}`,
143147
],
144148
}),
145149
],

0 commit comments

Comments
 (0)