AWS CDK: Api Key ignored when testing api gateway locally?

Viewed 277

I'm currently developping an API with aws-cdk and I'm testing it locally with aws-sam-cli and docker. I wanted to add the requirement of an API Key to call the API.

Here is the code inside my stack:

const api = new apigw.RestApi(this, "MyAPI", {
  restApiName: "My API",
  description: "BLABLABLA API",
});

const myLambdaIntegration = new apigw.LambdaIntegration(myLambda, {
  proxy: false,
});

// Endpoints of the API
api.root.addResource("test").addMethod("GET", myLambdaIntegration, {
  apiKeyRequired: true,
});

Then I build this stack and synth it (npm run build ; cdk synth --no-staging myStack > template.yaml And try to test it locally sam local start-api

When I request my api without any API KEY, the API returns me the result of my lambda.

I expected it to return me an error like {"message":"Missing Authentication Token"}

Does anyone have an idea of what is going on? I suspect it's because authorizations are ignored locally but didn't find anything about that...

Thanks in advance!

Edit: After deploying this stack, the API correctly asks me for a token.

0 Answers
Related