I've set my pipeline to invoke a AWS Lamba function. After running for 30 mins it shows the error
The AWS Lambda function cloudfront-invalidation failed to return a result. Check the function to verify that it has permission to call the PutJobSuccessResult action and that it made a call to PutJobSuccessResult.
Lambda Role has Permissions to set PutJobSuccessResult and Codepipeline Service role has permission to invoke lambda functions.
Here is my lambda code:
import boto3
import time
def lambda_handler(context, event):
sts_connection = boto3.client('sts')
acct_b = sts_connection.assume_role(
RoleArn="arn:aws:iam::1234567890:role/AssumeRole",
RoleSessionName="cross_acct_lambda"
)
ACCESS_KEY = acct_b['Credentials']['AccessKeyId']
SECRET_KEY = acct_b['Credentials']['SecretAccessKey']
SESSION_TOKEN = acct_b['Credentials']['SessionToken']
client = boto3.client(
'cloudfront',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
aws_session_token=SESSION_TOKEN,
)
response = client.create_invalidation(
DistributionId='ABC',
InvalidationBatch={
'Paths': {
'Quantity': 1,
'Items': [
'/*',
]
},
'CallerReference': str(time.time()).replace(".", "")
}
)
invalidation_id = response['Invalidation']['Id']
print("Invalidation created successfully with Id: " + invalidation_id)
pipeline = boto3.client('codepipeline')
response = pipeline.put_job_success_result(
jobId= event['CodePipeline.job']['id']
)
return response
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "logs:*" ], "Effect": "Allow", "Resource": "arn:aws:logs:*:*:*" }, { "Action": [ "codepipeline:PutJobSuccessResult", "codepipeline:PutJobFailureResult" ], "Effect": "Allow", "Resource": "*" } ] }Codepipeline Role Policy: AWSLambdaBasicExecutionRole - SUBHAS PATIL