addHeader.go - AWS Code Sample


Adds a custom header to a DynamoDB table.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "" "" "" "" "fmt" "os" ) func main() { // Initialize a session in us-west-2 that the SDK will use to load credentials // from the shared config file. (~/.aws/credentials). sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, ) if err != nil { fmt.Println("Error getting session:") fmt.Println(err) os.Exit(1) } // Create DynamoDB client // and expose HTTP requests/responses svc := dynamodb.New(sess, aws.NewConfig().WithLogLevel(aws.LogDebugWithHTTPBody)) // Add "CustomHeader" header with value of 10 svc.Handlers.Send.PushFront(func(r *request.Request) { r.HTTPRequest.Header.Set("CustomHeader", fmt.Sprintf("%d", 10)) }) // Call ListTables just to see HTTP request/response // The request should have the CustomHeader set to 10 _, _ = svc.ListTables(&dynamodb.ListTablesInput{}) }

Sample Details

Service: dynamodb

Last tested: 2018-03-16

Author: Doug-AWS

Type: full-example