I have a piece of code which is failing and I am trying to debug using AWS Cloudwatch logs. The piece of code, with logging enabled is as follows:
def run_command(args, cwd):
try:
proc = subprocess.run(args,
cwd=cwd,
timeout=720,
check=True,
capture_output=True)
stdout = proc.stdout
stderr = proc.stderr
except subprocess.TimeoutExpired as e:
logging.debug(proc.stdout)
print(e.output)
print(e)
I expect the subprocess output to be displayed in my AWS Cloudwatch logs. However, here is the output:
START RequestId: 1234567 Version: $LATEST
Command '['my command']' returned non-zero exit status 1.
END RequestId: 1234567
I am running the function like: run_command('ls',cwd)
.
I am expecting more information on the second line, as I added the capture_output=True
statement. Why is the output of the subprocess command not being logged to my Cloudwatch group, and is it possible to do this?
Thanks
The policy attached to the lambda function is as follows:
- PolicyName: CoreFunctionality
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:DeleteObject
- s3:ListBucket
Resource:
- !Sub "${S3Bucket.Arn}/*"
- !Sub "${S3Bucket.Arn}"
I've omitted the secrets manager and obtaining the secret value, to be safe.