本文整理汇总了Golang中github.com/aws/aws-sdk-go/aws.StringSlice函数的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice函数的具体用法?Golang StringSlice怎么用?Golang StringSlice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringSlice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildUpdateStackInput
func (s *CloudFormationStack) buildUpdateStackInput(stackName string, stackDetails StackDetails) *cloudformation.UpdateStackInput {
updateStackInput := &cloudformation.UpdateStackInput{
StackName: aws.String(stackName),
TemplateURL: aws.String(stackDetails.TemplateURL),
}
if len(stackDetails.Capabilities) > 0 {
updateStackInput.Capabilities = aws.StringSlice(stackDetails.Capabilities)
}
if len(stackDetails.NotificationARNs) > 0 {
updateStackInput.NotificationARNs = aws.StringSlice(stackDetails.NotificationARNs)
}
if len(stackDetails.Parameters) > 0 {
updateStackInput.Parameters = BuilCloudFormationParameters(stackDetails.Parameters)
}
if len(stackDetails.ResourceTypes) > 0 {
updateStackInput.ResourceTypes = aws.StringSlice(stackDetails.ResourceTypes)
}
if stackDetails.StackPolicyURL != "" {
updateStackInput.StackPolicyURL = aws.String(stackDetails.StackPolicyURL)
}
return updateStackInput
}
示例2: tagSpotRequests
func (clst *amazonCluster) tagSpotRequests(awsIDs []awsID) error {
OuterLoop:
for region, ids := range groupByRegion(awsIDs) {
session := clst.getSession(region)
spotIDs := getSpotIDs(ids)
var err error
for i := 0; i < 30; i++ {
_, err = session.CreateTags(&ec2.CreateTagsInput{
Tags: []*ec2.Tag{
{
Key: aws.String(clst.namespace),
Value: aws.String(""),
},
},
Resources: aws.StringSlice(spotIDs),
})
if err == nil {
continue OuterLoop
}
time.Sleep(5 * time.Second)
}
log.Warn("Failed to tag spot requests: ", err)
session.CancelSpotInstanceRequests(
&ec2.CancelSpotInstanceRequestsInput{
SpotInstanceRequestIds: aws.StringSlice(spotIDs),
})
return err
}
return nil
}
示例3: setDocumentPermissions
func setDocumentPermissions(d *schema.ResourceData, meta interface{}) error {
ssmconn := meta.(*AWSClient).ssmconn
log.Printf("[INFO] Setting permissions for document: %s", d.Id())
permission := d.Get("permissions").(map[string]interface{})
ids := aws.StringSlice([]string{permission["account_ids"].(string)})
if strings.Contains(permission["account_ids"].(string), ",") {
ids = aws.StringSlice(strings.Split(permission["account_ids"].(string), ","))
}
permInput := &ssm.ModifyDocumentPermissionInput{
Name: aws.String(d.Get("name").(string)),
PermissionType: aws.String(permission["type"].(string)),
AccountIdsToAdd: ids,
}
_, err := ssmconn.ModifyDocumentPermission(permInput)
if err != nil {
return errwrap.Wrapf("[ERROR] Error setting permissions for SSM document: {{err}}", err)
}
return nil
}
示例4: convertToContainerDef
// convertToContainerDef transforms each service in the compose yml
// to an equivalent container definition
func convertToContainerDef(inputCfg *libcompose.ServiceConfig,
volumes map[string]string, outputContDef *ecs.ContainerDefinition) error {
// setting memory
var mem int64
if inputCfg.MemLimit != 0 {
mem = inputCfg.MemLimit / kiB / kiB // convert bytes to MiB
}
if mem == 0 {
mem = defaultMemLimit
}
// convert environment variables
// TODO, read env file
environment := []*ecs.KeyValuePair{}
for _, env := range inputCfg.Environment.Slice() {
parts := strings.SplitN(env, "=", 2)
name := &parts[0]
var value *string
if len(parts) > 1 {
value = &parts[1]
}
environment = append(environment, &ecs.KeyValuePair{
Name: name,
Value: value,
})
}
// convert port mappings
portMappings, err := convertToPortMappings(*outputContDef.Name, inputCfg.Ports)
if err != nil {
return err
}
// convert volumes from
volumesFrom := []*ecs.VolumeFrom{}
for _, val := range inputCfg.VolumesFrom {
volumeFrom := &ecs.VolumeFrom{
SourceContainer: aws.String(val),
}
volumesFrom = append(volumesFrom, volumeFrom)
}
// convert mount points
mountPoints, err := convertToMountPoints(inputCfg.Volumes, volumes)
if err != nil {
return err
}
// populating container definition, offloading the validation to aws-sdk
outputContDef.Cpu = aws.Int64(inputCfg.CpuShares)
outputContDef.Memory = aws.Int64(mem)
outputContDef.EntryPoint = aws.StringSlice(inputCfg.Entrypoint.Slice())
outputContDef.Command = aws.StringSlice(inputCfg.Command.Slice())
outputContDef.Environment = environment
outputContDef.Image = aws.String(inputCfg.Image)
outputContDef.Links = aws.StringSlice(inputCfg.Links.Slice()) //TODO, read from external links
outputContDef.MountPoints = mountPoints
outputContDef.PortMappings = portMappings
outputContDef.VolumesFrom = volumesFrom
return nil
}
示例5: Stop
func (clst amazonCluster) Stop(machines []Machine) error {
var awsIDs []awsID
for _, m := range machines {
awsIDs = append(awsIDs, awsID{
region: m.Region,
spotID: m.ID,
})
}
for region, ids := range groupByRegion(awsIDs) {
session := clst.getSession(region)
spotIDs := getSpotIDs(ids)
spots, err := session.DescribeSpotInstanceRequests(
&ec2.DescribeSpotInstanceRequestsInput{
SpotInstanceRequestIds: aws.StringSlice(spotIDs),
})
if err != nil {
return err
}
instIds := []string{}
for _, spot := range spots.SpotInstanceRequests {
if spot.InstanceId != nil {
instIds = append(instIds, *spot.InstanceId)
}
}
if len(instIds) > 0 {
_, err = session.TerminateInstances(&ec2.TerminateInstancesInput{
InstanceIds: aws.StringSlice(instIds),
})
if err != nil {
return err
}
}
_, err = session.CancelSpotInstanceRequests(
&ec2.CancelSpotInstanceRequestsInput{
SpotInstanceRequestIds: aws.StringSlice(spotIDs),
})
if err != nil {
return err
}
if err := clst.wait(ids, false); err != nil {
return err
}
}
return nil
}
示例6: dropGeneratedSecurityGroup
func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string {
conn := meta.(*AWSClient).ec2conn
groups := strings.Split(settingValue, ",")
// Check to see if groups are ec2-classic or vpc security groups
ec2Classic := true
beanstalkSGRegexp := "sg-[0-9a-fA-F]{8}"
for _, g := range groups {
if ok, _ := regexp.MatchString(beanstalkSGRegexp, g); ok {
ec2Classic = false
break
}
}
var resp *ec2.DescribeSecurityGroupsOutput
var err error
if ec2Classic {
resp, err = conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
GroupNames: aws.StringSlice(groups),
})
} else {
resp, err = conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
GroupIds: aws.StringSlice(groups),
})
}
if err != nil {
log.Printf("[DEBUG] Elastic Beanstalk error describing SecurityGroups: %v", err)
return settingValue
}
log.Printf("[DEBUG] Elastic Beanstalk using ec2-classic security-groups: %t", ec2Classic)
var legitGroups []string
for _, group := range resp.SecurityGroups {
log.Printf("[DEBUG] Elastic Beanstalk SecurityGroup: %v", *group.GroupName)
if !strings.HasPrefix(*group.GroupName, "awseb") {
if ec2Classic {
legitGroups = append(legitGroups, *group.GroupName)
} else {
legitGroups = append(legitGroups, *group.GroupId)
}
}
}
sort.Strings(legitGroups)
return strings.Join(legitGroups, ",")
}
示例7: convertMapToSlice
// convertMapToSlice converts the map [String -> bool] to a AWS String Slice that is used by our APIs as input
func convertMapToSlice(mapItems map[string]bool) []*string {
sliceItems := make([]string, 0, len(mapItems))
for key := range mapItems {
sliceItems = append(sliceItems, key)
}
return aws.StringSlice(sliceItems)
}
示例8: resourceAwsVPCEndpointRouteTableAssociationDelete
func resourceAwsVPCEndpointRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
endpointId := d.Get("vpc_endpoint_id").(string)
rtId := d.Get("route_table_id").(string)
input := &ec2.ModifyVpcEndpointInput{
VpcEndpointId: aws.String(endpointId),
RemoveRouteTableIds: aws.StringSlice([]string{rtId}),
}
_, err := conn.ModifyVpcEndpoint(input)
if err != nil {
ec2err, ok := err.(awserr.Error)
if !ok {
return fmt.Errorf("Error deleting VPC Endpoint/Route Table association: %s", err.Error())
}
switch ec2err.Code() {
case "InvalidVpcEndpointId.NotFound":
fallthrough
case "InvalidRouteTableId.NotFound":
fallthrough
case "InvalidParameter":
log.Printf("[DEBUG] VPC Endpoint/Route Table association is already gone")
default:
return fmt.Errorf("Error deleting VPC Endpoint/Route Table association: %s", err.Error())
}
}
log.Printf("[DEBUG] VPC Endpoint/Route Table association %q deleted", d.Id())
d.SetId("")
return nil
}
示例9: resourceAwsVPCEndpointRouteTableAssociationCreate
func resourceAwsVPCEndpointRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
endpointId := d.Get("vpc_endpoint_id").(string)
rtId := d.Get("route_table_id").(string)
_, err := findResourceVPCEndpoint(conn, endpointId)
if err != nil {
return err
}
log.Printf(
"[INFO] Creating VPC Endpoint/Route Table association: %s => %s",
endpointId, rtId)
input := &ec2.ModifyVpcEndpointInput{
VpcEndpointId: aws.String(endpointId),
AddRouteTableIds: aws.StringSlice([]string{rtId}),
}
_, err = conn.ModifyVpcEndpoint(input)
if err != nil {
return fmt.Errorf("Error creating VPC Endpoint/Route Table association: %s", err.Error())
}
id := vpcEndpointIdRouteTableIdHash(endpointId, rtId)
log.Printf("[DEBUG] VPC Endpoint/Route Table association %q created.", id)
d.SetId(id)
return resourceAwsVPCEndpointRouteTableAssociationRead(d, meta)
}
示例10: dropGeneratedSecurityGroup
func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string {
conn := meta.(*AWSClient).ec2conn
groups := strings.Split(settingValue, ",")
resp, err := conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
GroupIds: aws.StringSlice(groups),
})
if err != nil {
log.Printf("[DEBUG] Elastic Beanstalk error describing SecurityGroups: %v", err)
return settingValue
}
var legitGroups []string
for _, group := range resp.SecurityGroups {
log.Printf("[DEBUG] Elastic Beanstalk SecurityGroup: %v", *group.GroupName)
if !strings.HasPrefix(*group.GroupName, "awseb") {
legitGroups = append(legitGroups, *group.GroupId)
}
}
sort.Strings(legitGroups)
return strings.Join(legitGroups, ",")
}
示例11: RunTaskWithOverrides
// RunTask issues a run task request for the input task definition
func (client *ecsClient) RunTaskWithOverrides(taskDefinition, startedBy string, count int, overrides map[string]string) (*ecs.RunTaskOutput, error) {
commandOverrides := []*ecs.ContainerOverride{}
for cont, command := range overrides {
contOverride := &ecs.ContainerOverride{
Name: aws.String(cont),
Command: aws.StringSlice([]string{command}),
}
commandOverrides = append(commandOverrides, contOverride)
}
ecsOverrides := &ecs.TaskOverride{
ContainerOverrides: commandOverrides,
}
resp, err := client.client.RunTask(&ecs.RunTaskInput{
Cluster: aws.String(client.params.Cluster),
TaskDefinition: aws.String(taskDefinition),
StartedBy: aws.String(startedBy),
Count: aws.Int64(int64(count)),
Overrides: ecsOverrides,
})
if err != nil {
log.WithFields(log.Fields{
"task definition": taskDefinition,
"error": err,
}).Error("Error running tasks")
}
return resp, err
}
示例12: TestStringValueSlice
func TestStringValueSlice(t *testing.T) {
for idx, in := range testCasesStringValueSlice {
if in == nil {
continue
}
out := aws.StringValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := aws.StringSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
示例13: GetEc2PrivateIpsFromInstanceIds
func GetEc2PrivateIpsFromInstanceIds(ec2_obj *ec2.EC2, instance_ids []string, debug bool) ([]string, error) {
params := &ec2.DescribeInstancesInput{
InstanceIds: aws.StringSlice(instance_ids),
}
resp, err := ec2_obj.DescribeInstances(params)
if err != nil {
return []string{}, fmt.Errorf("Cannot retrieve EC2 instance information: %s", FormatAwsError(err))
}
if len(resp.Reservations) <= 0 {
return []string{}, fmt.Errorf("No EC2 instances found (Reservations.*) with specified Instance IDs filter: ", strings.Join(instance_ids, ", "))
}
if len(resp.Reservations[0].Instances) <= 0 {
return []string{}, fmt.Errorf("No EC2 instances found (Reservations[0].* with specified Instance IDs filter: ", strings.Join(instance_ids, ", "))
}
var result []string
for idx, _ := range resp.Reservations {
for _, value := range resp.Reservations[idx].Instances {
if *value.State.Name == "running" {
result = append(result, *value.PrivateIpAddress)
} else {
if debug == true {
fmt.Println(*value.InstanceId, "is not in a running state, excluded from results.")
}
}
}
}
if len(result) == 0 {
return []string{}, fmt.Errorf("No running EC2 instances found in result set, cannot proceed.")
}
return result, nil
}
示例14: GetEc2InstanceIdsFromContainerInstances
func GetEc2InstanceIdsFromContainerInstances(ecs_obj *ecs.ECS, cluster string, container_instances []string, debug bool) ([]string, error) {
params := &ecs.DescribeContainerInstancesInput{
Cluster: aws.String(cluster),
ContainerInstances: aws.StringSlice(container_instances),
}
resp, err := ecs_obj.DescribeContainerInstances(params)
if err != nil {
return []string{}, fmt.Errorf("Cannot retrieve ECS container instance information: %s", FormatAwsError(err))
}
if len(resp.ContainerInstances) <= 0 {
return []string{}, fmt.Errorf("No ECS container instances found with specified filter - cluster:", cluster, "- instances:", strings.Join(container_instances, ", "))
}
var result []string
for _, value := range resp.ContainerInstances {
if *value.Status == "ACTIVE" {
result = append(result, *value.Ec2InstanceId)
} else {
if debug == true {
fmt.Println(*value.Ec2InstanceId, "is not in an ACTIVE state, excluded from results.")
}
}
}
if len(result) == 0 {
return []string{}, fmt.Errorf("No running ECS container instances found in result set, cannot proceed.")
}
return result, nil
}
示例15: getQueueAttributes
func (s *SQSQueue) getQueueAttributes(queueURL string) (map[string]string, error) {
getQueueAttributesInput := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String(queueURL),
AttributeNames: aws.StringSlice([]string{"All"}),
}
s.logger.Debug("get-queue-attributes", lager.Data{"input": getQueueAttributesInput})
getQueueAttributesOutput, err := s.sqssvc.GetQueueAttributes(getQueueAttributesInput)
if err != nil {
s.logger.Error("aws-sqs-error", err)
if awsErr, ok := err.(awserr.Error); ok {
if reqErr, ok := err.(awserr.RequestFailure); ok {
// AWS SQS returns a 400 if Queue is not found
if reqErr.StatusCode() == 400 || reqErr.StatusCode() == 404 {
return nil, ErrQueueDoesNotExist
}
}
return nil, errors.New(awsErr.Code() + ": " + awsErr.Message())
}
return nil, err
}
s.logger.Debug("get-queue-attributes", lager.Data{"output": getQueueAttributesOutput})
return aws.StringValueMap(getQueueAttributesOutput.Attributes), nil
}