本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/cloudformation.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleCloudFormation_ValidateTemplate
func ExampleCloudFormation_ValidateTemplate() {
svc := cloudformation.New(nil)
params := &cloudformation.ValidateTemplateInput{
TemplateBody: aws.String("TemplateBody"),
TemplateURL: aws.String("TemplateURL"),
}
resp, err := svc.ValidateTemplate(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例2: ExampleCloudFormation_ContinueUpdateRollback
func ExampleCloudFormation_ContinueUpdateRollback() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := cloudformation.New(sess)
params := &cloudformation.ContinueUpdateRollbackInput{
StackName: aws.String("StackNameOrId"), // Required
ResourcesToSkip: []*string{
aws.String("ResourceToSkip"), // Required
// More values...
},
RoleARN: aws.String("RoleARN"),
}
resp, err := svc.ContinueUpdateRollback(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例3: ExampleCloudFormation_ListStacks
func ExampleCloudFormation_ListStacks() {
svc := cloudformation.New(nil)
params := &cloudformation.ListStacksInput{
NextToken: aws.String("NextToken"),
StackStatusFilter: []*string{
aws.String("StackStatus"), // Required
// More values...
},
}
resp, err := svc.ListStacks(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例4: ExampleCloudFormation_SignalResource
func ExampleCloudFormation_SignalResource() {
svc := cloudformation.New(nil)
params := &cloudformation.SignalResourceInput{
LogicalResourceId: aws.String("LogicalResourceId"), // Required
StackName: aws.String("StackNameOrId"), // Required
Status: aws.String("ResourceSignalStatus"), // Required
UniqueId: aws.String("ResourceSignalUniqueId"), // Required
}
resp, err := svc.SignalResource(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例5: StackExists
// StackExists returns whether the given stackName or stackID currently exists
func StackExists(stackNameOrID string, awsSession *session.Session, logger *logrus.Logger) (bool, error) {
cf := cloudformation.New(awsSession)
describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackNameOrID),
}
describeStacksOutput, err := cf.DescribeStacks(describeStacksInput)
logger.WithFields(logrus.Fields{
"DescribeStackOutput": describeStacksOutput,
}).Debug("DescribeStackOutput results")
exists := false
if err != nil {
logger.WithFields(logrus.Fields{
"DescribeStackOutputError": err,
}).Debug("DescribeStackOutput")
// If the stack doesn't exist, then no worries
if strings.Contains(err.Error(), "does not exist") {
exists = false
} else {
return false, err
}
} else {
exists = true
}
return exists, nil
}
示例6: ExampleCloudFormation_EstimateTemplateCost
func ExampleCloudFormation_EstimateTemplateCost() {
svc := cloudformation.New(nil)
params := &cloudformation.EstimateTemplateCostInput{
Parameters: []*cloudformation.Parameter{
{ // Required
ParameterKey: aws.String("ParameterKey"),
ParameterValue: aws.String("ParameterValue"),
UsePreviousValue: aws.Bool(true),
},
// More values...
},
TemplateBody: aws.String("TemplateBody"),
TemplateURL: aws.String("TemplateURL"),
}
resp, err := svc.EstimateTemplateCost(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例7: ExampleCloudFormation_GetStackPolicy
func ExampleCloudFormation_GetStackPolicy() {
svc := cloudformation.New(nil)
params := &cloudformation.GetStackPolicyInput{
StackName: aws.String("StackName"), // Required
}
resp, err := svc.GetStackPolicy(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS Error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例8: StackEvents
// StackEvents returns the slice of cloudformation.StackEvents for the given stackID or stackName
func StackEvents(stackID string,
eventFilterLowerBound time.Time,
awsSession *session.Session) ([]*cloudformation.StackEvent, error) {
cfService := cloudformation.New(awsSession)
var events []*cloudformation.StackEvent
nextToken := ""
for {
params := &cloudformation.DescribeStackEventsInput{
StackName: aws.String(stackID),
}
if len(nextToken) > 0 {
params.NextToken = aws.String(nextToken)
}
resp, err := cfService.DescribeStackEvents(params)
if nil != err {
return nil, err
}
for _, eachEvent := range resp.StackEvents {
if eachEvent.Timestamp.After(eventFilterLowerBound) {
events = append(events, eachEvent)
}
}
if nil == resp.NextToken {
break
} else {
nextToken = *resp.NextToken
}
}
return events, nil
}
示例9: New
func New(config Config) (*Client, error) {
credentials := credentials.NewStaticCredentials(config.AccessKey, config.SecretKey, "")
sdkConfig := &aws.Config{
Credentials: credentials,
Region: aws.String(config.Region),
}
session := session.New(sdkConfig)
if config.CloudFormationWaitTimeout == 0 {
return nil, fmt.Errorf("AWS config CloudFormationWaitTimeout must be a positive timeout")
}
ec2EndpointConfig, err := config.getEndpoint("ec2")
if err != nil {
return nil, err
}
cloudformationEndpointConfig, err := config.getEndpoint("cloudformation")
if err != nil {
return nil, err
}
iamEndpointConfig, err := config.getEndpoint("iam")
if err != nil {
return nil, err
}
return &Client{
EC2: ec2.New(session, ec2EndpointConfig),
CloudFormation: cloudformation.New(session, cloudformationEndpointConfig),
IAM: iam.New(session, iamEndpointConfig),
Clock: clockImpl{},
CloudFormationWaitTimeout: config.CloudFormationWaitTimeout,
}, nil
}
示例10: ActiveStacks
func ActiveStacks(region string) ([]string, error) {
var stack_names []string
svc := cloudformation.New(session.New(), &aws.Config{Region: aws.String(region)})
params := &cloudformation.ListStacksInput{
StackStatusFilter: []*string{
aws.String("CREATE_COMPLETE"),
aws.String("UPDATE_COMPLETE"),
aws.String("UPDATE_ROLLBACK_COMPLETE"),
},
}
resp, err := svc.ListStacks(params)
if err != nil {
return nil, err
}
for _, element := range resp.StackSummaries {
stack_names = append(stack_names, *element.StackName)
}
sort.Strings(stack_names)
return stack_names, nil
}
示例11: getInstanceInfo
func (d *Driver) getInstanceInfo() error {
svc := cloudformation.New(session.New())
params := &cloudformation.DescribeStacksInput{
StackName: aws.String(d.MachineName),
}
resp, err := svc.DescribeStacks(params)
if err != nil {
return err
}
for _, element := range resp.Stacks[0].Outputs {
outputV := *element.OutputValue
if *element.OutputKey == "PrivateIp" {
d.PrivateIPAddress = outputV
}
if *element.OutputKey == "InstanceID" {
d.InstanceId = outputV
}
if *element.OutputKey == "IpAddress" {
d.IPAddress = outputV
}
}
return nil
}
示例12: stackAvailable
func (d *Driver) stackAvailable() (bool, error) {
log.Debug("Checking if the stack is available......")
svc := cloudformation.New(session.New())
params := &cloudformation.DescribeStacksInput{
StackName: aws.String(d.MachineName),
}
resp, err := svc.DescribeStacks(params)
log.Debug(resp)
if err != nil {
return false, err
}
if *resp.Stacks[0].StackStatus == cloudformation.StackStatusRollbackInProgress || *resp.Stacks[0].StackStatus == cloudformation.StackStatusRollbackComplete {
return false, errors.New("Stack Rollback Occured")
}
if *resp.Stacks[0].StackStatus == cloudformation.StackStatusCreateComplete {
return true, nil
} else {
log.Debug("Stack Not Available Yet")
return false, nil
}
}
示例13: followStackEvents
func followStackEvents(c *cli.Context) {
// Defaults
cmdTimout := 600 * time.Second
checkInteval := 15 * time.Second
// Keep the last lot of stack events
var preStackEvents []*cloudformation.StackEvent
svc := cloudformation.New(&aws.Config{Region: aws.String("us-west-2")})
params := &cloudformation.DescribeStackEventsInput{
StackName: aws.String("test-stack"),
}
preStackEvents = periodicCommand(svc, params, preStackEvents)
ticker := time.NewTicker(checkInteval)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
preStackEvents = periodicCommand(svc, params, preStackEvents)
case <-quit:
ticker.Stop()
return
}
}
}()
time.Sleep(cmdTimout)
}
示例14: Example
func Example() {
// create a backend that implements the subset of the AWS API you need
fakeBackend := &CloudFormationBackend{}
// start a local HTTP server that dispatches requests to the backend
fakeServer := httptest.NewServer(awsfaker.New(fakeBackend))
// configure and use your client. this might be a separate process,
// with the endpoint override set via environment variable or other config
client := cloudformation.New(session.New(&aws.Config{
Credentials: credentials.NewStaticCredentials("some-access-key", "some-secret-key", ""),
Region: aws.String("some-region"),
Endpoint: aws.String(fakeServer.URL), // override the default AWS endpoint
}))
out, err := client.CreateStack(&cloudformation.CreateStackInput{
StackName: aws.String("some-stack"),
})
if err != nil {
panic(err)
}
fmt.Printf("[Client] CreateStack returned ID: %q\n", *out.StackId)
_, err = client.CreateStack(&cloudformation.CreateStackInput{
StackName: aws.String("some-stack"),
})
fmt.Printf("[Client] CreateStack returned error:\n %s\n", err)
// Output:
// [Server] CreateStack called on "some-stack"
// [Client] CreateStack returned ID: "some-id"
// [Server] CreateStack called on "some-stack"
// [Client] CreateStack returned error:
// AlreadyExistsException: Stack [some-stack] already exists
// status code: 400, request id:
}
示例15: ExampleCloudFormation_GetTemplate
func ExampleCloudFormation_GetTemplate() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := cloudformation.New(sess)
params := &cloudformation.GetTemplateInput{
ChangeSetName: aws.String("ChangeSetNameOrId"),
StackName: aws.String("StackName"),
TemplateStage: aws.String("TemplateStage"),
}
resp, err := svc.GetTemplate(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}