matt brown
matt brown

Reputation: 50

AWS APIGateway lambda authorizer caching policy even after setting ttl to zero

I am using an APIGateway lambda Authorizer with the following policy generation code but seems like even after setting the time to live on the authorizer lambda to zero still the policy is getting cached for some reason.

This is my code:

var generatePolicy = function(principalId, effect, resource) {
    var authResponse = {};

    authResponse.principalId = principalId;
    if (effect && resource) {
        var policyDocument = {};
        policyDocument.Version = '2012-10-17'; 
        policyDocument.Statement = [];
        var statementOne = {};
        statementOne.Action = 'execute-api:Invoke'; 
        statementOne.Effect = effect;
        statementOne.Resource = resource.replace(/:function:.+$/, ':function:*');
        policyDocument.Statement[0] = statementOne;
        authResponse.policyDocument = policyDocument;
    }

    authResponse.context = {
        "stringKey": "stringval",
        "numberKey": 123,
        "booleanKey": true
        };
        return authResponse;
    }
}

Upvotes: 2

Views: 1170

Answers (1)

amittn
amittn

Reputation: 2355

  • Try changing the statementOne.Resource = '*'; this will work.
  • For a valid policy, API Gateway caches the returned policy, associated with the incoming token or identity source request parameters.

Upvotes: 1

Related Questions