我正在尝试向正在运行的 ubuntu ec2 实例发送命令。我已经配置了适当的角色,并且在 ec2 实例上运行了一个 ssm 代理。使用 boto3 SDK,我能够使用该client.send_command()
函数成功发送 shell 命令,随后能够获取命令 ID。现在的挑战是轮询结果。我正在尝试使用该 client.get_command_invocation()
功能,但一直出现InvocationDoesNotExist
错误。我确信我使用的是正确的命令 ID 和实例 ID,因为我已经使用 AWS CLI 对它们进行了测试, aws ssm list-command-invocations --command-id #### --instance-id i-#####
并且效果很好。这是我的代码片段:
`ssm_client = boto3.client('ssm')
target_id = "i-####"
response = ssm_client.send_command(
InstanceIds=[
target_id
],
DocumentName="AWS-RunShellScript",
Comment="Code to run" ,
Parameters={
"commands": ["ls -l"]
}
)
cmd_id= response['Command']['CommandId']
response = ssm_client.get_command_invocation(CommandId=cmd_id,
InstanceId=target_id)
print(response)`
Run Code Online (Sandbox Code Playgroud)
这是返回的错误:
botocore.errorfactory.InvocationDoesNotExist: An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation
提前致谢。
我正在尝试使用boto3在EC2实例上运行ssh命令.我读了这本指南:http: //docs.aws.amazon.com/AWSEC2/latest/UserGuide/troubleshooting-remote-commands.html 我做了他们在那里写的所有内容,但我一直收到错误信息:
>>>import boto3
>>> ec2 = boto3.client('ssm')
>>> a = ec2.send_command(InstanceIds=['i-0d5e16f6'], DocumentName='AWS-RunShellScript', Comment='abcdabcd', Parameters={"commands":["ifconfig"]})
Run Code Online (Sandbox Code Playgroud)
输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 253, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 543, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation:
Run Code Online (Sandbox Code Playgroud)
如果我正在尝试用awscli发送命令,我会遇到同样的问题:
aws ssm send-command --instance-ids "i-0d5e16f6" --document-name "AWS-RunShellScript" --comment "IP config" --parameters commands=ifconfig --output text
An error occurred (InvalidInstanceId) when calling the …
Run Code Online (Sandbox Code Playgroud) 我正在Kotlin编写一个SSM项目,只要我尝试用一个类(一个服务实现)注释,就会发生这种情况@Service
.
open
已添加.context:component-scan
已配置.java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'seckillServiceImpl' defined in file [blahblah\target\classes\service\impl\SeckillServiceImpl.class]: Unexpected exception during …
Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个代码,我可以在其中访问然后修改和更新 SSM 参数值。
任何人,你能让我知道如何用 boto3 实现这一点吗?
在我的第一个aws 帐户上,我按以下方式指定了参数:
/config/a => value1
/config/b => value2
/config/c/a => value31
/config/c/b => value32
Run Code Online (Sandbox Code Playgroud)
我想将这些移动到我的第二个aws 帐户。
我在参数存储中手动创建了这些参数。
如何轻松地将这些值从一个帐户复制到另一个帐户?
使用aws ssm get-parameters --names "<param-name>"
会有点太困难,因为我有太多的参数。
amazon-web-services ssm amazon-systems-manager aws-parameter-store
我正在尝试在我的 nodejs 项目中获取 ssm 参数,我是 IAM 凭证,并在我的弹性 beanstalk 实例中编写了一个测试并且可以正常工作。问题出在项目内部。任何想法为什么?
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var ssm = new AWS.SSM();
var options = {
Name: '/test/test', /* required */
WithDecryption: false
};
var parameterPromise = ssm.getParameter(options).promise();
parameterPromise.then(function(data, err) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Run Code Online (Sandbox Code Playgroud) 我有一个场景,我使用 CodePipeline 将我的 cdk 项目从一个工具帐户部署到多个环境帐户。我的管道部署方式是cdk deploy
从 CodeBuild 作业中运行。
我的团队决定使用 SSM 参数存储来存储配置,最终我们在环境帐户中获得了一些参数,例如resources/vpc/id
我可以在部署时间 => 中读取的 VPC_ID ( ) ssm.StringParameter.valueForStringParameter
。
但是,其他参数位于工具帐户中,例如我的环境帐户 ( environment/nonprod/account/id
) 中的帐户 ID 和其他全局配置。我在获取这些值时遇到问题。
目前,我能想到的唯一方法是使用一个步骤来读取上一步中的所有这些值并将它们加载到上下文值中。
对于这个问题有更优雅的方法吗?我希望我可以指定从哪个帐户获取 SSM 值。有任何想法吗?
谢谢。
我已在 AWS SSM 参数存储 UI 中将键值对配置为my-ssm-key
= ssm-value
。
我有以下基于无服务器构建的 CF YAML 模板:
service: redirect-test
provider:
name: aws
runtime: python3.8
environment:
ssm_value: '{{resolve:ssm:my-ssm-key:1}}'
ssm_value_is_correct: !If [SSM_KEY_IS_CORRECT, yes, no]
functions:
hello:
handler: handler.hello
resources:
Conditions:
SSM_KEY_IS_CORRECT:
!Equals
- '{{resolve:ssm:my-ssm-key:1}}'
- 'ssm-value'
Run Code Online (Sandbox Code Playgroud)
在部署堆栈时,环境变量被设置为ssm_value
=ssm-value
和ssm_value_is_correct
= no
。
为什么条件语句解析为“否”而不是“是”?在条件中使用 SSM 参数存储值的正确方法是什么?
amazon-web-services aws-cloudformation ssm serverless-framework
我已在私有子网中创建了一个 EC2 实例(即路由表没有附加 Internet 网关)。
附加到私有子网的路由表将 0.0.0.0/0 路由到 NAT 网关。
EC2 实例具有正确的 SSM 角色并显示在 SSM 托管实例列表中。
我可以通过会话管理器在实例上启动会话。
但是,当我从路由表中删除 NAT 网关映射时,会话连接无法连接。
我的理解是 NAT 仅用于传出流量。因此,我假设会话管理器连接是通过内部 AWS 网络而不是公共互联网路由的,因为该实例无法访问。但是我不明白为什么该实例试图通过公共互联网路由流量。我原本预计,要将自身注册为 SSM 托管实例,实例上的 SSM 代理将需要互联网访问。但我不明白为什么会话管理器会要求实例具有互联网访问权限?
谢谢。
我正在尝试使用 AWS Systems Manager 会话管理器连接到我的 EC2 实例。
\n这些是私有 EC2 实例,没有公共 IP,位于 VPC 中的私有子网上,可通过 NAT 网关访问 Internet。
\n网络 ACL 已完全开放(入站和出站),但没有允许 SSH 访问实例的安全组。
\n我完成了所有会话管理器先决条件(SSM 代理、Amazon Linux 2 AMI),但是,当我尝试通过 AWS 控制台连接到实例时,我收到一个红色警告标志:“我们无法\xe2\x80\x99连接到您的实例。常见原因包括“.
\n然后,如果我向允许 SSH 访问(入站端口 22)的实例添加安全组并等待几秒钟,重复相同的连接过程,红色警告不会出现,我可以连接到该实例。
\n尽管我知道这些实例是安全的(它们没有公共 IP 并且位于私有子网中),但我并不期望会话管理器要求向它们打开 SSH 端口。事实上,官方文档称其好处之一是:“无需开放入站端口,无需管理堡垒主机或 SSH 密钥”。
\n我搜索了相关帖子但找不到任何具体内容。有什么想法我可能会错过吗?
\n谢谢!
\n