lambda.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aws
  15. import (
  16. "fmt"
  17. "net/url"
  18. )
  19. type LambdaFunction struct {
  20. Description string `json:"Description"`
  21. TracingConfig struct {
  22. Mode string `json:"Mode"`
  23. } `json:"TracingConfig"`
  24. VpcConfig string `json:"VpcConfig"`
  25. SigningJobArn string `json:"SigningJobArn"`
  26. SnapStart struct {
  27. OptimizationStatus string `json:"OptimizationStatus"`
  28. ApplyOn string `json:"ApplyOn"`
  29. } `json:"SnapStart"`
  30. RevisionID string `json:"RevisionId"`
  31. LastModified string `json:"LastModified"`
  32. FileSystemConfigs string `json:"FileSystemConfigs"`
  33. FunctionName string `json:"FunctionName"`
  34. Runtime string `json:"Runtime"`
  35. Version string `json:"Version"`
  36. PackageType string `json:"PackageType"`
  37. LastUpdateStatus string `json:"LastUpdateStatus"`
  38. Layers string `json:"Layers"`
  39. FunctionArn string `json:"FunctionArn"`
  40. KMSKeyArn string `json:"KMSKeyArn"`
  41. MemorySize int `json:"MemorySize"`
  42. ImageConfigResponse string `json:"ImageConfigResponse"`
  43. LastUpdateStatusReason string `json:"LastUpdateStatusReason"`
  44. DeadLetterConfig string `json:"DeadLetterConfig"`
  45. Timeout int `json:"Timeout"`
  46. Handler string `json:"Handler"`
  47. CodeSha256 string `json:"CodeSha256"`
  48. Role string `json:"Role"`
  49. SigningProfileVersionArn string `json:"SigningProfileVersionArn"`
  50. MasterArn string `json:"MasterArn"`
  51. RuntimeVersionConfig string `json:"RuntimeVersionConfig"`
  52. CodeSize int `json:"CodeSize"`
  53. State string `json:"State"`
  54. StateReason string `json:"StateReason"`
  55. LoggingConfig struct {
  56. LogFormat string `json:"LogFormat"`
  57. ApplicationLogLevel string `json:"ApplicationLogLevel"`
  58. LogGroup string `json:"LogGroup"`
  59. SystemLogLevel string `json:"SystemLogLevel"`
  60. } `json:"LoggingConfig"`
  61. Environment string `json:"Environment"`
  62. EphemeralStorage struct {
  63. Size int `json:"Size"`
  64. } `json:"EphemeralStorage"`
  65. StateReasonCode string `json:"StateReasonCode"`
  66. LastUpdateStatusReasonCode string `json:"LastUpdateStatusReasonCode"`
  67. Architectures []string `json:"Architectures"`
  68. }
  69. func (self *SRegion) ListFunctions() ([]LambdaFunction, error) {
  70. params := url.Values{}
  71. params.Set("MaxItems", "10000")
  72. params.Set("FunctionVersion", "ALL")
  73. ret, marker := []LambdaFunction{}, ""
  74. for {
  75. part := struct {
  76. Functions []LambdaFunction
  77. NextMarker string
  78. }{}
  79. if len(marker) > 0 {
  80. params.Set("Marker", marker)
  81. }
  82. path := fmt.Sprintf("/2015-03-31/functions/?%s", params.Encode())
  83. err := self.lambdaRequest("ListFunctions", path, map[string]interface{}{}, &part)
  84. if err != nil {
  85. return nil, err
  86. }
  87. ret = append(ret, part.Functions...)
  88. if len(part.Functions) == 0 || len(part.NextMarker) == 0 {
  89. break
  90. }
  91. marker = part.NextMarker
  92. }
  93. return ret, nil
  94. }
  95. type ProvisionedConcurrencyConfig struct {
  96. RequestedProvisionedConcurrentExecutions int
  97. }
  98. func (self *SRegion) GetProvisionedConcurrencyConfig(funcName, qualifier string) (*ProvisionedConcurrencyConfig, error) {
  99. params := map[string]interface{}{}
  100. ret := &ProvisionedConcurrencyConfig{}
  101. path := fmt.Sprintf("/2019-09-30/functions/%s/provisioned-concurrency?Qualifier=%s", funcName, qualifier)
  102. err := self.lambdaRequest("GetProvisionedConcurrencyConfig", path, params, &ret)
  103. if err != nil {
  104. return nil, err
  105. }
  106. return ret, nil
  107. }