作者:yuishu
项目:ape
// 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)
}
作者:eliza
项目:ape
// 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
}
作者:DavidTPat
项目:ape
// 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)
}
作者:kujoh
项目:ape
// 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)
}
作者:pilwo
项目:ape
func Test_Sha256(t *testing.T) {
s := utils.Sha256([]byte("Hello World"))
assert.Equal(t, "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=", s)
}