title: Invalidate cloudfront cache
body: <p>I want to invaliate cloudfront cache as last build step in codepipeline.
  I created lambda function (node):</p>
  
  <pre><code>exports.handler = (event, context, callback) =&gt; {
  const aws = require('aws-sdk'),
  cloudfront = new aws.CloudFront({apiVersion: '2018-06-18'}),
  codepipeline = new aws.CodePipeline(),
  jobId = event["CodePipeline.job"].id,
  paramsCloudFront = {
    DistributionId: 'distr_id',
    InvalidationBatch: {
      CallerReference: `Date.now()`,
      Paths: {
        Quantity: 1,
        Items: ['/*',]
      }
    }
  },
  putJobSuccess = function(message) {
      var params = {
          jobId: jobId
      };
      codepipeline.putJobSuccessResult(params, (err, data) =&gt; {
          if(err) {
              context.fail(err);      
          } else {
              context.succeed(message);      
          }
      });
  },
  putJobFailure = function(message) {
      var params = {
          jobId: jobId,
          failureDetails: {
              message: JSON.stringify(message),
              type: 'JobFailed',
              externalExecutionId: context.invokeid
          }
      };
      codepipeline.putJobFailureResult(params, (err, data) =&gt; {
          context.fail(message);      
      });
  }
  
  
  cloudfront.createInvalidation(paramsCloudFront, (err, data) =&gt; {
    if (err) {
      putJobFailure(err)
    } else {
      putJobSuccess(data)
    }
  });
  </code></pre>
  
  <p>};</p>
  
  <p>Codepipeline reports stage is successful but no invalidation in cloudfront is created. No errors in cloudwatch. 
  In IAM I gave full access to cloudfront to both lambda and codepipeline.
  What is wrogn?</p>