首页 > 其他分享 >AWS - Sample Go code to use secrets

AWS - Sample Go code to use secrets

时间:2023-12-17 19:25:14浏览次数:31  
标签:use code err secrets aws secretsmanager go config

 

// Use this code snippet in your app.
// If you need more information about configurations or implementing the sample code, visit the AWS docs:   
// https://aws.github.io/aws-sdk-go-v2/docs/getting-started/

import (
    "context"
    "log"

    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
)

func main() {
    secretName := "zimple_bank"
    region := "ap-southeast-2"

    config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
    if err != nil {
        log.Fatal(err)
    }

    // Create Secrets Manager client
    svc := secretsmanager.NewFromConfig(config)

    input := &secretsmanager.GetSecretValueInput{
        SecretId:     aws.String(secretName),
        VersionStage: aws.String("AWSCURRENT"), // VersionStage defaults to AWSCURRENT if unspecified
    }

    result, err := svc.GetSecretValue(context.TODO(), input)
    if err != nil {
        // For a list of exceptions thrown, see
        // https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
        log.Fatal(err.Error())
    }

    // Decrypts secret using the associated KMS key.
    var secretString string = *result.SecretString

    // Your code goes here.
}

 

标签:use,code,err,secrets,aws,secretsmanager,go,config
From: https://www.cnblogs.com/zhangzhihui/p/17909580.html

相关文章

  • [LeetCode] LeetCode373. 查找和最小的K对数字
    题目描述思路:大顶堆+翻转注意:该题有问题,代码可以通过测试用例。方法一:classSolution{publicList<List<Integer>>kSmallestPairs(int[]nums1,int[]nums2,intk){PriorityQueue<Node>heap=newPriorityQueue<>((e1,e2)->e2.sum-e1.sum);......
  • Codeforces Round 867 (Div. 3)
    CodeforcesRound867(Div.3)A:ABCD(E差一点点,最后把那种特殊情况想出来然后没写上去就结束了)A.TubeTubeFeed题意:给两个数组分别是时间和价值,要价值最大但是只能选一个思路:最开始以为是01背包,结果只选一个,一个一个枚举就行#include<bits/stdc++.h>usingnamespace......
  • Codeforces Round 855 (Div. 3)
    CodeforcesRound855(Div.3)A.IsItaCat?题意:要求:字符串必须以只包含字母"m"或"M"的非空序列开始必须紧跟由'e'或'E'字符组成的非空序列必须紧接着仅由字符'o'或'O'组成的非空序列必须紧接着是仅由字符'w'或'W'组成的非空序列思路:一个一个来(WA了三发注意这几......
  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)A:ABCA.Rook简单题,就两个循环搞定(直接上码)#include<bits/stdc++.h>usingnamespacestd;voidsolve(){chara;intb;cin>>a>>b;for(inti=1;i<=8;i++){if(i!=b){......
  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)A.InsertDigit题意:插入一个字母使得这个数字最大化思路:只要从前往后便利就行#include<iostream>usingnamespacestd;voidsolve(){intn,k;cin>>n>>k;boolx=true,y=false;for(inti=0;i<n;i++){......
  • Codeforces Round 913 (Div. 3)
    CF1907总结A.Rook题面翻译给出车在国际象棋棋盘中的位置,输出其可到达的坐标(不必在意顺序)。车可以横着或竖着走任意格数。分析题意明了,输出车所在行和列所有格子的序号(除车所在位置外)。code#include<bits/stdc++.h>usingnamespacestd;intt;voidsolve(){ string......
  • Codeforces Round 891 (Div3)
    CodeforcesRound891(Div.3)A.ArrayColoring这个我vp的时候写复杂了,想不到答案的思路这么清晰,将两部分分别看,将偶数加进去其奇偶性不变,只有奇数加进去才会改变奇偶性,so只有改变偶数次奇偶性才能使其奇偶性相同,所以cnt%2==0.#include<bits/stdc++.h>usingnamespacestd;......
  • Codeforces Round 816 (Div. 2) VP
    基本情況A秒了,B错一次之后也过了,C没思路。B.BeautifulArrayProblem-B-Codeforcesvoidsolve(){ longlongn,k,b,s; memset(ans,0,sizeof(ans)); std::cin>>n>>k>>b>>s; if(s<b*k){std::cout<<"-1\n";ret......
  • AtCoder Beginner Contest 325
    C-Sensors但看数据发现是经典油田问题,直接dfs#include<bits/stdc++.h>usingnamespacestd;intn,m;intdx[8]={-1,-1,-1,0,1,1,1,0};intdy[8]={-1,0,1,1,1,0,-1,-1};intvis[1005][1005];charmp[1005][1005];voiddfs(intx,inty){ vis[x][y]=......
  • AtCoder Beginner Contest 332
    C-T-shirts题意是:给定一个string,字符代表每天有不同的事,做不同的事会穿不同的衣服,问你最少需要准备多少T恤。思路:贪心,能不用T恤就不要T恤#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intn,k; cin>>n>>k; strings; cin>>s; intans=0; intcnt=k; i......