aws cloudwatch get-metric-statistics
--namespace AWS/Lambda
--metric-name Invocations
--start-time 2020-01-01T00:00:00Z
--end-time 2020-06-01T00:00:00Z
--period 3600
--statistics "Sum"
--dimensions "Name=FunctionName,Value=my-function"
import boto3 import logging
logging.basicConfig() logging.getLogger().setLevel(logging.INFO)
def lambda_handler(event, context): # Your code here
# Log the number of invocations
cw = boto3.client('cloudwatch')
cw.put_metric_data(
Namespace='NAMESPACE',
MetricData=[
{
'MetricName': 'Invocations',
'Dimensions': [
{
'Name': 'FunctionName',
'Value': context.function_name
}
],
'Unit': 'Count',
'Value': 1
}
]
)
logging.info('Invocation count incremented.')