Exemplo n.º 1
0
// DeployCode generates a zip and creates or updates the function.
func (f *Function) DeployCode() error {
	f.Log.Info("deploying")

	zip, err := f.ZipBytes()
	if err != nil {
		return err
	}

	info, err := f.Info()

	if e, ok := err.(awserr.Error); ok {
		if e.Code() == "ResourceNotFoundException" {
			return f.Create(zip)
		}
	}

	if err != nil {
		return err
	}

	remoteHash := *info.Configuration.CodeSha256
	localHash := utils.Sha256(zip)

	if localHash == remoteHash {
		f.Log.Info("unchanged")
		return nil
	}

	return f.Update(zip)
}
Exemplo n.º 2
0
// UpdateFunctionCode stub.
func (l *Lambda) UpdateFunctionCode(in *lambda.UpdateFunctionCodeInput) (*lambda.FunctionConfiguration, error) {
	res, err := l.GetFunction(&lambda.GetFunctionInput{
		FunctionName: in.FunctionName,
	})

	if err != nil {
		return nil, err
	}

	size := uint64(len(in.ZipFile))
	checksum := utils.Sha256(in.ZipFile)
	remoteChecksum := *res.Configuration.CodeSha256
	remoteSize := uint64(*res.Configuration.CodeSize)

	if checksum != remoteChecksum {
		l.create("function", *in.FunctionName, map[string]interface{}{
			"size": fmt.Sprintf("%s -> %s", humanize.Bytes(remoteSize), humanize.Bytes(size)),
		})
	}

	out := &lambda.FunctionConfiguration{
		Version: aws.String("$LATEST"),
	}

	return out, nil
}
Exemplo n.º 3
0
// DeployCode deploys function code when changed.
func (f *Function) DeployCode(zip []byte, config *lambda.GetFunctionOutput) error {
	remoteHash := *config.Configuration.CodeSha256
	localHash := utils.Sha256(zip)

	if localHash == remoteHash {
		f.Log.Info("code unchanged")
		return nil
	}

	f.Log.WithFields(log.Fields{
		"local":  localHash,
		"remote": remoteHash,
	}).Debug("code changed")

	return f.Update(zip)
}
Exemplo n.º 4
0
// DeployCode generates a zip and creates or updates the function.
func (f *Function) DeployCode() error {
	f.Log.Info("deploying")

	zip, err := f.BuildBytes()
	if err != nil {
		return err
	}

	if err := f.hookDeploy(); err != nil {
		return err
	}

	config, err := f.GetConfig()

	if e, ok := err.(awserr.Error); ok {
		if e.Code() == "ResourceNotFoundException" {
			return f.Create(zip)
		}
	}

	if err != nil {
		return err
	}

	remoteHash := *config.Configuration.CodeSha256
	localHash := utils.Sha256(zip)

	if localHash == remoteHash {
		f.Log.Info("unchanged")
		return nil
	}

	f.Log.WithFields(log.Fields{
		"local":  localHash,
		"remote": remoteHash,
	}).Debug("changed")

	return f.Update(zip)
}
Exemplo n.º 5
0
func Test_Sha256(t *testing.T) {
	s := utils.Sha256([]byte("Hello World"))
	assert.Equal(t, "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=", s)
}