首页 > 解决方案 > Aws cli 命令始终在 us-east-1 区域中为容器化 SNS 创建主题

问题描述

    **Dockerfile**:
    
    FROM java:8-jre-alpine
    
    EXPOSE 9911
    
    VOLUME /etc/sns
    
    ENV AWS_DEFAULT_REGION=us-east-2 \
        AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX \
        AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
        DB_PATH=/etc/sns/db.json
    
    # aws-cli
    RUN apk -Uuv add python py-pip && \
        pip install awscli && \
        apk --purge -v del py-pip && \
        rm /var/cache/apk/*
    
    ARG VERSION=0.3.0version: "3"
    
    services:
      aws-sns:
        build: .
        image: aws-sns-test:latest
        volumes:
          - ./config:/etc/sns
        expose:
          - 9911
        ports:
         - 9911:9911
        hostname: aws-sns
        enter code here
    
    ADD https://github.com/s12v/sns/releases/download/$VERSION/sns-$VERSION.jar /sns.jar
    
    CMD ["java", "-jar", "/sns.jar"]
    

    **docker-compose.yml:**
    
    version: "3"
    
    services:
      aws-sns:
        build: .
        image: aws-sns-test:latest
        volumes:
          - ./config:/etc/sns
        expose:
          - 9911
        ports:
         - 9911:9911
        hostname: aws-sns
        
 Later I also set the env variables using aws configure but this also didn't work.
aws configure
    AWS Access Key ID [****************XXXX]:
    AWS Secret Access Key [****************XXXX]:
    Default region name [us-east-2]:
    Default output format [None]:

我后来也在 sns conatiner 中设置了这些变量(例如 docker exec -it 39cb43921b31(conatinerid) sh),但我没有得到想要的输出。

输出
aws --endpoint-url=http://localhost:9911 sns create-topic --name local_sns {“TopicArn”:“arn:aws:sns:us-east-1:123456789012:local_sns”}
预期输出
aws --endpoint-url=http://localhost:9911 sns create-topic --name local_sns { "TopicArn": "arn:aws:sns:us-east-2:123456789012:local_sns" }

标签: amazon-web-servicesdockerdocker-composeaws-cliamazon-sns

解决方案


您无法更改区域,因为它已硬编码到源代码中:

 val topic = Topic(s"arn:aws:sns:us-east-1:123456789012:$name", name)

您使用的 AWS 凭证无效,因为它们可以是任何东西,因此 AWS CLI 不会抱怨。您还可以使用--no-sign-requestaws cli 选项来消除对凭据的需要。


推荐阅读