amazon-web-services - 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" }
解决方案
您无法更改区域,因为它已硬编码到源代码中:
val topic = Topic(s"arn:aws:sns:us-east-1:123456789012:$name", name)
您使用的 AWS 凭证无效,因为它们可以是任何东西,因此 AWS CLI 不会抱怨。您还可以使用--no-sign-request
aws cli 选项来消除对凭据的需要。
推荐阅读
- php - php检查getvalue不为空
- python - 无法在 heroku 上发布 Django Rest API
- python - 我的播放器图片在移动过程中模糊
- javascript - Is there a way to register a global helper file for Handlebar.js?
- excel - 在具有字符串“总利率”的单元格下方执行 if 语句?
- discord.js - Discord JS v12:如何通过 ID 获取消息的内容?
- javascript - 如何将 html 包装到 javascript 变量中并传递给刀片?
- gcc - 就机器代码而言,在 GCC、clang 和/或 LLVM 中实现的架构支持在哪里?
- django - AWS Lightsail“处理 WSGI 脚本时发生异常”
- ansible - with_items 中的多个变量出错