我想使用 AWS CDK 在我的 lambda 上启用 DynamoDB 流,我可以这样做,但我也想在 lambda 上启用过滤条件
但我收到此错误:
过滤器模式定义无效。(服务:AWSLambda;状态代码:400;错误代码:InvalidParameterValueException
这是我从 DynamoDB 流中收到的事件:
{
"input": {
"Records": [
{
"eventID": "e92e0072a661a06df0e62e411f",
"eventName": "INSERT",
"eventVersion": "1.1",
"eventSource": "aws:dynamodb",
"awsRegion": "<region>",
"dynamodb": {
"ApproximateCreationDateTime": 1639500357,
"Keys": {
"service": {
"S": "service"
},
"key": {
"S": "key"
}
},
"NewImage": {
"service": {
"S": "service"
},
"channel": {
"S": "email"
},
"key": {
"S": "key"
}
},
"SequenceNumber": "711500000000015864417",
"SizeBytes": 168,
"StreamViewType": "NEW_IMAGE"
},
"eventSourceARN": "arn:aws:dynamodb:<region>:<account>:table/table-name/stream/2021-12-14T13:00:29.888"
}
]
},
"env": …Run Code Online (Sandbox Code Playgroud) 我有由 cdk cli(typecript-language) 生成的代码:
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as appsync from '@aws-cdk/aws-appsync';
export class BookStoreGraphqlApiStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const api = new appsync.GraphqlApi(this, 'MyApi', {
name: 'my-book-api',
schema: appsync.Schema.fromAsset('graphql/schema.graphql')
});
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'BookStoreGraphqlApiStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesize
Run Code Online (Sandbox Code Playgroud)
我的package.json: …
这是 codebuild 使用的 buildspec.yml 文件:
version: 0.2
env:
shell: bash
phases:
install:
runtime-versions:
nodejs: 14
pre_build:
commands:
- echo Installing source NPM dependencies...
- npm install -g aws-cdk
- npm install -g typescript
- npm install
- npm run build
build:
commands:
- cdk --version
- cdk ls
- cdk synth
post_build:
Run Code Online (Sandbox Code Playgroud)
/usr/local/bin/cdk -> /usr/local/lib/node_modules/aws-cdk/bin/cdk npm 警告 notsup 不支持 aws-cdk@2.9.0 引擎:想要:{"node":">= 14.15.0"}(当前:{"node":"12.22.2","npm":"6.14.13"})npm WARN notsup 与您的node/npm 版本不兼容:aws-cdk@2.9.0
最后cdk ls失败
感谢任何帮助,因为我已经尝试删除 node-modules 和 package-lock.json。
我RDS用这个脚本制作了cdk.
它使用户myname成为管理员,但是我在哪里可以获得密码?
另外,有没有办法通过脚本设置默认密码?
const dbInstance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.mysql({
version: rds.MysqlEngineVersion.VER_8_0_19,
}),
vpc,
instanceIdentifier:`st-${targetEnv}-rds`,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
publiclyAccessible: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
databaseName:`stybot${targetEnv}`,
credentials: rds.Credentials.fromGeneratedSecret('myname')
});
Run Code Online (Sandbox Code Playgroud) 我想使用 AWS CDK 更新 SSM 参数。
我的用例:在第一个堆栈中,我正在创建 SSM 参数。在第二个堆栈中想要更新(更改)它。我遇到的解决方案之一是使用 lambda,我想避免它。
是通过 CDK 更新现有参数的方法吗?cfn_param.set_value
第一个堆栈:
class ParamSetupStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
ssm.StringParameter( self,
f'PIPELINE-PARAM-1',
parameter_name="parma-1",
string_value="SOME STRING VALUE",
description="Desctiption of ...."
)
Run Code Online (Sandbox Code Playgroud)
第二个堆栈:
class UpdateParamStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
template = cfn_inc.CfnInclude(self, "Template",
template_file="PATH/TO/ParamSetupStack.json",
preserve_logical_ids=False)
cfn_param = template.get_resource("PIPELINE-PARAM-1")
cfn_param.set_value("NEW VALUE")
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 AWS-CDK 将相当基本的 Nodejs CRUD API 部署到 AWS。该服务在 Docker 容器中运行,我将其部署到 ALB 后面的 ECS Fargate 集群。我在 Route53 中也有一个我正在尝试使用的域。
我遇到的问题是我似乎无法通过域访问 ALB。我可以通过 HTTP 使用其默认 AWS DNS (XXXXX.us-west-2.elb.amazonaws.com/) 直接访问 ALB,但当我尝试通过域访问它时,出现 504 超时。
我对 AWS 和 CDK 还很陌生,所以我确信我在这里遗漏了一些明显的东西。任何建议或推荐的资源/示例将不胜感激。这是我的 CDK 代码:
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as Cloudfront from "aws-cdk-lib/aws-cloudfront";
import * as CloudfrontOrigins from "aws-cdk-lib/aws-cloudfront-origins";
import * as Route53 from "aws-cdk-lib/aws-route53";
import * as Route53Targets from "aws-cdk-lib/aws-route53-targets";
import * as ACM from "aws-cdk-lib/aws-certificatemanager";
import * …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-cloudfront docker aws-fargate aws-cdk
尝试设置一个Cloudfront行为来使用Lambda 函数 url,代码如下:
this.distribution = new Distribution(this, id + "Distro", {
comment: id + "Distro",
defaultBehavior: {
origin: new S3Origin(s3Site),
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
},
additionalBehaviors: {
[`api-prd-v2/*`]: {
compress: true,
originRequestPolicy: originRequestPolicy,
origin: new HttpOrigin(functionUrl.url, {
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
originSslProtocols: [OriginSslPolicy.TLS_V1_2],
}),
allowedMethods: AllowedMethods.ALLOW_ALL,
viewerProtocolPolicy: ViewerProtocolPolicy.HTTPS_ONLY,
cachePolicy: apiCachePolicy,
},
Run Code Online (Sandbox Code Playgroud)
该functionUrl对象在不同的堆栈中创建并传入堆栈cloudformation,定义如下:
this.functionUrl = new FunctionUrl(this, 'LambdaApiUrl', {
function: this.lambdaFunction,
authType: FunctionUrlAuthType.NONE,
cors: {
allowedOrigins: ["*"],
allowedMethods: [HttpMethod.GET, HttpMethod.POST],
allowCredentials: true,
maxAge: Duration.minutes(1)
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码失败,因为“参数源名称不能包含冒号”。据推测,这是因为 …
从 cloudformation 中删除 CDKToolkit 堆栈并尝试使用 \ncdk bootstrap --profile stage-profile 命令重新创建它后会引发错误
\xe2\x8f\xb3 Bootstrapping environment aws://123456/eu-central-1...\nTrusted accounts for deployment: (none)\nTrusted accounts for lookup: (none)\nUsing default execution policy of 'arn:aws:iam::aws:policy/AdministratorAccess'. Pass '--cloudformation-execution-policies' to customize.\nCDKToolkit: creating CloudFormation changeset...\n4:11:35 PM | CREATE_FAILED | AWS::SSM::Parameter | CdkBootstrapVersion\nERROR Parameter Name /cdk-bootstrap/******/version with a different configuration already exists.\n\n\xe2\x9d\x8c Environment aws://123456/eu-central-1 failed bootstrapping: Error: The stack named CDKToolkit failed creation, \nit may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: ERROR Parameter Name /cdk-bootstrap/******/version with …Run Code Online (Sandbox Code Playgroud) 我想使用 AWS Typescript CDK 创建 DynamoDB 表和备份。使用 CDK 创建 DynamoDB 非常简单,但实施备份并不容易。谁能帮我使用 CDK 实现备份?我试图解决这个问题,但互联网上没有足够的参考资料。如果有人能够提供此场景的完整示例,我将不胜感激。提前致谢。
我尝试使用这个https://aws-cdk.com/aws-backup/,但并不是很有帮助。
我们正在使用触发 lambda 的 cdk 在堆栈中创建 aws 自定义资源。在我们的例子中,如果 lambda 中发生任何故障,它会向自定义资源发送故障信号,并且自定义资源会触发自动回滚到堆栈的先前版本。我们想要阻止这种情况发生。我们的要求是,如果 lambda 失败,自定义资源堆栈仅显示失败状态并且不会触发任何回滚部署。
有没有办法使用 cdk 在堆栈上设置禁用回滚属性
amazon-web-services aws-cdk aws-cloudformation-custom-resource aws-cdk-custom-resource
aws-cdk ×10
aws-lambda ×2
node.js ×2
amazon-rds ×1
aws-appsync ×1
aws-cloudformation-custom-resource ×1
aws-fargate ×1
aws-ssm ×1
backup ×1
buildspec ×1
docker ×1
graphql ×1
typescript ×1