func getLastPointFromCloudWatch(cw cloudwatchiface.CloudWatchAPI, functionName string, metric metricsGroup) (*cloudwatch.Datapoint, error) {
	now := time.Now()
	statsInput := make([]*string, len(metric.Metrics))
	for i, typ := range metric.Metrics {
		statsInput[i] = aws.String(typ.Type)
	}
	input := &cloudwatch.GetMetricStatisticsInput{
		StartTime:  aws.Time(now.Add(time.Duration(180) * time.Second * -1)),
		EndTime:    aws.Time(now),
		MetricName: aws.String(metric.CloudWatchName),
		Period:     aws.Int64(60),
		Statistics: statsInput,
		Namespace:  aws.String(namespace),
	}
	if functionName != "" {
		input.Dimensions = []*cloudwatch.Dimension{{
			Name:  aws.String("FunctionName"),
			Value: aws.String(functionName),
		}}
	}
	response, err := cw.GetMetricStatistics(input)
	if err != nil {
		return nil, err
	}
	datapoints := response.Datapoints
	if len(datapoints) == 0 {
		return nil, nil
	}
	latest := new(time.Time)
	var latestDp *cloudwatch.Datapoint
	for _, dp := range datapoints {
		if dp.Timestamp.Before(*latest) {
			continue
		}
		latest = dp.Timestamp
		latestDp = dp
	}
	return latestDp, nil
}
getLastPoint fetches a CloudWatch metric and parse
package mpawslambda
import (
	"flag"
	"log"
	"strings"
	"time"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudwatch"
	"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
	mp "github.com/mackerelio/go-mackerel-plugin-helper"
)
const (
	namespace          = "AWS/Lambda"
	metricsTypeAverage = "Average"
	metricsTypeSum     = "Sum"
	metricsTypeMaximum = "Maximum"
	metricsTypeMinimum = "Minimum"
)
type metricsGroup struct {
	CloudWatchName string
	Metrics        []metric
}
type metric struct {
	MackerelName string
	Type         string
}
type LambdaPlugin struct {
	FunctionName string
	Prefix       string
	AccessKeyID     string
	SecretAccessKey string
	Region          string
	CloudWatch *cloudwatch.CloudWatch
}
func (p LambdaPlugin) MetricKeyPrefix() string {
	return p.Prefix
}
func (p *LambdaPlugin) prepare() error {
	sess, err := session.NewSession()
	if err != nil {
		return err
	}
	config := aws.NewConfig()
	if p.AccessKeyID != "" && p.SecretAccessKey != "" {
		config = config.WithCredentials(credentials.NewStaticCredentials(p.AccessKeyID, p.SecretAccessKey, ""))
	}
	if p.Region != "" {
		config = config.WithRegion(p.Region)
	}
	p.CloudWatch = cloudwatch.New(sess, config)
	return nil
}