我继承了一个小型 CDK 项目,其中包含一个cdk.context.json
文件:
{
"vpc-provider:account=9015xxxxxxxx:filter.tag:Name=preprod-eu-west-1:region=eu-west-1:returnAsymmetricSubnets=true": {
"vpcId": "vpc-0d891xxxxxxxxxxxx",
"vpcCidrBlock": "172.35.0.0/16",
"availabilityZones": [],
"subnetGroups": [
{
"name": "Private",
"type": "Private",
"subnets": [
{
"subnetId": "subnet-0ad04xxxxxxxxxxxx",
"cidr": "172.35.a.0/22",
"availabilityZone": "eu-west-1b",
"routeTableId": "rtb-0fee4xxxxxxxxxxxx"
},
{
"subnetId": "subnet-08598xxxxxxxxxxxx",
"cidr": "172.35.z.0/22",
"availabilityZone": "eu-west-1c",
"routeTableId": "rtb-0f477xxxxxxxxxxxx"
}
]
},
{
"name": "Public",
"type": "Public",
"subnets": [
{
"subnetId": "subnet-0fba3xxxxxxxxxxxx",
"cidr": "172.35.y.0/22",
"availabilityZone": "eu-west-1b",
"routeTableId": "rtb-02dfbxxxxxxxxxxxx"
},
{
"subnetId": "subnet-0a3b8xxxxxxxxxxxx",
"cidr": "172.35.x.0/22",
"availabilityZone": "eu-west-1c",
"routeTableId": "rtb-02dfbxxxxxxxxxxxx"
}
]
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
这对于它连接到的预生产环境来说效果很好,但我现在需要部署到生产环境。我可以手动生成相同的文件,但这感觉像是浪费时间 - 我怀疑这是一个生成的文件。 …
这是我的代码:
const mailerFunction = new aws_lambda_nodejs.NodejsFunction(this, 'ApiNotificationHandler', {
runtime: lambda.Runtime.NODEJS_14_X,
memorySize: 1024,
timeout: cdk.Duration.seconds(3),
handler: 'main',
entry: path.join(__dirname, '../../src/mailer/index.ts'),
environment: {
SES_REGION,
SES_EMAIL_FROM,
SES_EMAIL_TO,
}
});
Run Code Online (Sandbox Code Playgroud)
我使用的是CDK 2.58.1版本。如何使用 cdk lambda 将额外的 html 文件上传到代码源?
您好,我正在开发 AWS CDK。我正在尝试为我的任务定义创建日志记录。我有下面的代码。
logDetail = logs.LogGroup(
self,
"MerchWebServicesLogGroup",
log_group_name="/projects/merchwebserviceslog/apiservices",
retention=logs.RetentionDays.SIX_MONTHS,
removal_policy=core.RemovalPolicy.DESTROY,
)
task_definition = ecs.Ec2TaskDefinition(
self, "TaskDef", execution_role=MWSECSTaskExecutionRole
)
container = task_definition.add_container(
"mw-service",
image=ecs.ContainerImage.from_registry(
"187628286232.dkr.ecr.ap-southeast-2.amazonaws.com/location/location-service:latest"
),
memory_limit_mib=3072,
logging=ecs.LogDriver.aws_logs(stream_prefix="mwservice", log_group=logDetail),
)
Run Code Online (Sandbox Code Playgroud)
这会产生
logDetail = logs.LogGroup(
self,
"MerchWebServicesLogGroup",
log_group_name="/projects/merchwebserviceslog/apiservices",
retention=logs.RetentionDays.SIX_MONTHS,
removal_policy=core.RemovalPolicy.DESTROY,
)
task_definition = ecs.Ec2TaskDefinition(
self, "TaskDef", execution_role=MWSECSTaskExecutionRole
)
container = task_definition.add_container(
"mw-service",
image=ecs.ContainerImage.from_registry(
"187628286232.dkr.ecr.ap-southeast-2.amazonaws.com/location/location-service:latest"
),
memory_limit_mib=3072,
logging=ecs.LogDriver.aws_logs(stream_prefix="mwservice", log_group=logDetail),
)
Run Code Online (Sandbox Code Playgroud)
问题是我不想传递任何 ExecutionRoleArn。如果我传递执行角色 ARN,我开始收到错误“无法初始化日志记录驱动程序”,否则工作正常。有人可以帮我解决这个问题吗?任何帮助,将不胜感激。谢谢
我使用 Glue Studio 创建了一个 AWS Glue 作业。它从 Glue 数据目录获取数据,进行一些转换,然后写入不同的数据目录。
配置目标节点时,我启用了运行后创建新分区的选项:
该作业成功运行,数据以正确的分区文件夹结构写入 S3,但在实际的数据目录表中没有创建新分区 - 我仍然需要运行 Glue Crawler 来创建它们。
生成的脚本中负责创建分区的代码如下(作业的最后两行):
DataSink0 = glueContext.write_dynamic_frame.from_catalog(frame = Transform4, database = "tick_test", table_name = "test_obj", transformation_ctx = "DataSink0", additional_options = {"updateBehavior":"LOG","partitionKeys":["date","provider"],"enableUpdateCatalog":True})
job.commit()
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?为什么没有创建新分区?如何避免运行爬网程序才能在 Athena 中获取可用数据?
我正在使用 Glue 2.0 - PySpark 2.4
amazon-web-services apache-spark-sql pyspark aws-glue aws-glue-spark
我目前正在参加AWS 现代化研讨会。当我添加 Amazon.CDK.AWS.EC2 nuget 库并构建应用程序时,出现以下错误:应用程序使用最新的 Amazon。来自 Nuget 的 CDK.Lib、Contructs、Amazon.CDK.AWS.EC2 库。我还尝试使用https://docs.aws.amazon.com/cdk/v2/guide/troubleshooting.html#troubleshooting_toolkitnpm update -g aws-cdk
中记录的故障排除步骤运行该命令,但这没有帮助。
我缺少什么?
构建错误:
Rebuild started...
1>------ Rebuild All started: Project: NorthwindCdk, Configuration: Debug Any CPU ------
Restored C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj (in 54 ms).
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.EC2 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.CloudWatch 1.137.0 requires Constructs (>= …
Run Code Online (Sandbox Code Playgroud) 这里是 IaC 项目结构:
\n./\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cdk.context.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package-lock.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sst.json\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 stacks\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 common\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Msk.js\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Vpc.js\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 posiciones\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Consumer.js\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 DocumentDB.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vistas\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Api.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Database.js\n
Run Code Online (Sandbox Code Playgroud)\nsst.json
是:
./\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cdk.context.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package-lock.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sst.json\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 stacks\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 common\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Msk.js\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Vpc.js\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 posiciones\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Consumer.js\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 DocumentDB.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vistas\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Api.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Database.js\n
Run Code Online (Sandbox Code Playgroud)\n和stacks/index.js
:
{\n "name": "rmo-serverless",\n "region": "us-west-2",\n …
Run Code Online (Sandbox Code Playgroud) 如何在 .NET 5 中获取当前的 UNIX 时间戳(以微秒为单位)?我环顾四周,只找到了一种以毫秒为单位的方法ToUnixTimeMilliseconds
,并且没有任何包含微秒的方法。
我可以像这样创建一个具有跨帐户委托的新托管区域
const parentZone = new route53.PublicHostedZone(this, 'HostedZone', {
zoneName: 'someexample.com',
crossAccountZoneDelegationPrincipal: new iam.AccountPrincipal('12345678901'),
crossAccountZoneDelegationRoleName: 'MyDelegationRole',
});
Run Code Online (Sandbox Code Playgroud)
这非常简单。但是如果托管区域已经存在怎么办
const parentHostedZone = route53.PublicHostedZone.fromLookup(this, 'HostedZone', {
domainName: 'someexample.com',
})
Run Code Online (Sandbox Code Playgroud)
如何向该区域添加委托?
我想要一个 lambda 创建 EventBridge 事件,但在调用 lambda 时出现此错误:
User: arn:aws:sts::120293923901:assumed-role/MyApiOrdersPostFunct-I1QOYC7P1R0Z/MyApiOrdersPostFunct-SJtAeYoiaguW is not authorized to perform: events:PutEvents on resource: arn:aws:events:eu-north-1:120293923901:event-bus/MyApiEventBus because no identity-based policy allows the events:PutEvents action
Run Code Online (Sandbox Code Playgroud)
我添加了政策但没有改变。
这是 lambda 调用 eventbridge。
User: arn:aws:sts::120293923901:assumed-role/MyApiOrdersPostFunct-I1QOYC7P1R0Z/MyApiOrdersPostFunct-SJtAeYoiaguW is not authorized to perform: events:PutEvents on resource: arn:aws:events:eu-north-1:120293923901:event-bus/MyApiEventBus because no identity-based policy allows the events:PutEvents action
Run Code Online (Sandbox Code Playgroud)
这是 CDK 配置。有两个策略(attachInlinePolicy、addToRolePolicy),因为我测试了这两个策略。
import { APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda';
import { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge';
const eventBridge = new EventBridgeClient({ region: 'eu-north-1' });
export const post: APIGatewayProxyHandler = …
Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-iam aws-lambda aws-cdk aws-event-bridge
我正在使用AWS Opensearch (Elasticsearch 6.8)
AWS lambda。当收到事件时,lambda 会将记录插入到 Elasticsearch 中。下面是elasticsearch的定义方式:
this.loggingES = new opensearch.Domain(this, 'LogsES', {
version: opensearch.EngineVersion.ELASTICSEARCH_6_8,
domainName: "app-logs-es",
vpc: this.loggingVPC,
zoneAwareness: {
availabilityZoneCount: 3,
},
enforceHttps: true,
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true
},
capacity: {
masterNodes: 3,
dataNodes: 3,
}
});
Run Code Online (Sandbox Code Playgroud)
现在发生的情况是,在同一个 VPC 下创建了两个安全组,一个用于 ES,另一个用于 lambda。lambda 无法连接到 Elasticsearch,因为 elasticsearch 安全组没有允许来自 lambda 安全组的流量的入站规则设置。
amazon-web-services amazon-vpc typescript aws-security-group aws-cdk
DataFrame 给出如下
df = pd.DataFrame({'col1' : [1,2,9,2,9,6], 'col2' : [13,4,5,4,5,0], 'col3' : [8,23,5,4,9,5]})
col1 col2 col3
0 1 13 8
1 2 4 23
2 9 5 5
3 2 4 4
4 9 5 9
5 6 0 5
Run Code Online (Sandbox Code Playgroud)
如何过滤此 DataFrame,以便仅获取 col1 和 col2 中都有重复项的行。所以最终 DataFrame 应该是这样的:
df_new
col1 col2 col3
0 2 4 23
1 2 4 5
2 9 5 4
3 9 5 9
Run Code Online (Sandbox Code Playgroud) aws-cdk ×7
aws-lambda ×2
python ×2
typescript ×2
.net ×1
.net-5 ×1
amazon-ecs ×1
amazon-iam ×1
amazon-vpc ×1
aws-glue ×1
c# ×1
dataframe ×1
devops ×1
filter ×1
node.js ×1
pyspark ×1