Skip to content

updates REST API examples and scopes permissions #7707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const httpLambdaIntegration = new HttpLambdaIntegration(
// create a new HTTP API with IAM as default authorizer
const httpApi = new HttpApi(apiStack, "HttpApi", {
apiName: "myHttpApi",
defaultAuthorizer: iamAuthorizer,
corsPreflight: {
// Modify the CORS settings below to match your specific requirements
allowMethods: [
Expand Down Expand Up @@ -137,7 +136,15 @@ httpApi.addRoutes({
// add a proxy resource path to the API
httpApi.addRoutes({
path: "/items/{proxy+}",
methods: [HttpMethod.OPTIONS, HttpMethod.ANY],
methods: [HttpMethod.ANY],
integration: httpLambdaIntegration,
authorizer: iamAuthorizer,
});

// add the options method to the route
httpApi.addRoutes({
path: "/items/{proxy+}",
methods: [HttpMethod.OPTIONS],
integration: httpLambdaIntegration,
});

Expand All @@ -155,8 +162,9 @@ const apiPolicy = new Policy(apiStack, "ApiPolicy", {
new PolicyStatement({
actions: ["execute-api:Invoke"],
resources: [
`${httpApi.arnForExecuteApi("items")}`,
`${httpApi.arnForExecuteApi("cognito-auth-path")}`,
`${httpApi.arnForExecuteApi("*", "/items")}`,
`${httpApi.arnForExecuteApi("*", "/items/*")}`,
`${httpApi.arnForExecuteApi("*", "/cognito-auth-path")}`,
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const apiStack = backend.createStack("api-stack");
const myRestApi = new RestApi(apiStack, "RestApi", {
restApiName: "myRestApi",
deploy: true,
deployOptions: {
stageName: "dev",
},
defaultCorsPreflightOptions: {
allowOrigins: Cors.ALL_ORIGINS, // Restrict this to domains you trust
allowMethods: Cors.ALL_METHODS, // Specify only the methods you need to allow
Expand Down Expand Up @@ -138,8 +141,9 @@ const apiRestPolicy = new Policy(apiStack, "RestApiPolicy", {
new PolicyStatement({
actions: ["execute-api:Invoke"],
resources: [
`${myRestApi.arnForExecuteApi("items")}`,
`${myRestApi.arnForExecuteApi("cognito-auth-path")}`,
`${myRestApi.arnForExecuteApi("*", "/items", "dev")}`,
`${myRestApi.arnForExecuteApi("*", "/items/*", "dev")}`,
`${myRestApi.arnForExecuteApi("*", "/cognito-auth-path", "dev")}`,
],
}),
],
Expand Down
Loading