Skip to content

Latest commit

 

History

History
76 lines (63 loc) · 3.69 KB

sdk-states.md

File metadata and controls

76 lines (63 loc) · 3.69 KB

dynamo db put item if not exists

Open in playground

export const main = asl.deploy.asStateMachine(async () => {
  void asl.sdk(DynamoDB).putItem({
    catch: [
      {
        errorEquals: ["DynamoDb.ConditionalCheckFailedException"],
        block: () => {
          //no op
        },
      },
    ],
    parameters: {
      Item: {
        pk: { S: "pk-value" },
        sk: { S: "sk-value" },
        string: { S: "value" },
        number: { N: "42" },
      },
      ConditionExpression: "attribute_not_exists(pk)",
      TableName: asl.deploy.getParameter("assignmentsTableName"),
    },
  });
});

count dynamo db items

Open in playground

export const main = asl.deploy.asStateMachine(async () => {
  const result = (await asl.sdk(DynamoDB).query({
    name: "COUNT(where gsi1pk === 'test')",
    parameters: {
      TableName: asl.deploy.getParameter("tableName"),
      IndexName: "GSI1",
      KeyConditionExpression: "#pk = :val",
      ExpressionAttributeNames: { "#pk": "gsi1pk" },
      ExpressionAttributeValues: { ":val": { S: "test" } },
      Select: "COUNT",
    },
  })) as { Count: number };
  return result.Count;
});

cloud watch put metric data

Open in playground

export const main = asl.deploy.asStateMachine(async () => {
  const value = 42;
  await asl.sdk(CloudWatch).putMetricData({
    name: "Publish Metric Data",
    parameters: {
      MetricData: [
        {
          MetricName: "ExampleMetric",
          Value: value,
        },
      ],
      Namespace: "ExampleNamespace",
    },
  });
});